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)

hth...
don

>
> 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

Attachment: pgpCl51TDL7hA.pgp
Description: PGP signature

Reply via email to