Re: how to tell that a file exists and is not 0-len?

2011-12-28 Thread Matthew Seaman
On 28/12/2011 23:50, Gary Kline wrote:

 access(filenamewithpath, F_OK) returned true  as Zero if i have
 access to it.  what do i use in C to tell me that a file is not  
 empty?  fstat?  or is there something more common?

stat(2) which uses the file path -- unless you have an open file
descriptor on the file, in which case use fstat(2).

Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.   7 Priory Courtyard
  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
JID: matt...@infracaninophile.co.uk   Kent, CT11 9PW



signature.asc
Description: OpenPGP digital signature


RE: how to tell that a file exists and is not 0-len?

2011-12-28 Thread Devin Teske
 -Original Message-
 From: owner-freebsd-questi...@freebsd.org [mailto:owner-freebsd-
 questi...@freebsd.org] On Behalf Of Gary Kline
 Sent: Wednesday, December 28, 2011 3:50 PM
 To: FreeBSD Mailing List
 Subject: how to tell that a file exists and is not 0-len?
 
 
 
 guys,
 
 access(filenamewithpath, F_OK) returned true  as Zero if i have access to it.
what
 do i use in C to tell me that a file is not empty?

This should do:

#include sys/types.h
#include sys/stat.h
...
struct stat sb;
off_t size;
if (!lstat(pathbuf, sb)) size = sb.st_size;
...

-- 
Devin

_
The information contained in this message is proprietary and/or confidential. 
If you are not the intended recipient, please: (i) delete the message and all 
copies; (ii) do not disclose, distribute or use the message in any manner; and 
(iii) notify the sender immediately. In addition, please be aware that any 
message addressed to our domain is subject to archiving and review by persons 
other than the intended recipient. Thank you.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org