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

Devin Teske devin.teske at
Wed Dec 28 23:59:26 UTC 2011

> -----Original Message-----
> From: owner-freebsd-questions at [mailto:owner-freebsd-
> questions at] 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.
> 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;


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.

More information about the freebsd-questions mailing list