testing for directory

Don Hinton don.hinton at vanderbilt.edu
Sun Apr 29 22:25:14 UTC 2007

On Sunday 29 April 2007 15:58:48 Roland Smith wrote:
> On Sun, Apr 29, 2007 at 04:39:42PM -0400, Robert Huff wrote:
> > 	In C code, is there a quick and dirty way to tell if a path
> > points to a directory?  Or do I have to open the parent directory and
> > check the entry for that name?

Just open() the path, then pass the fd to getdirentries(), if it returns -1, 
and errno = EINVAL, it's not a directory.  (man getdirentries for more info)


> Try opening the path in question for writing with open(2). If it returns
> -1, and errno is EISDIR, it is a directory.
> This will be inconclusive on a read-only filesystem, or if the limit of
> open file handles is reached, or for any other reason that can make
> open(2) fail.
> Roland

Don Hinton <don.hinton at vanderbilt.edu> or <hintonda at gmail.com>
Institute for Software Integrated Systems (ISIS), Vanderbilt University
tel: 615.480.5667 or 615.870.9728
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20070429/05310e60/attachment-0001.pgp

More information about the freebsd-questions mailing list