Re: testing for directory

2007-04-29 Thread Robert Huff

Jeffrey Goldberg writes:

>  >In C code, is there a quick and dirty way to tell if a path
>  > points to a directory?
>  
>  man 2 stat

This, I believe, will be the answer I'm looking for.
Thank you.


Robert Huff
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: testing for directory

2007-04-29 Thread Jeffrey Goldberg


On Apr 29, 2007, at 3:39 PM, Robert Huff wrote:



In C code, is there a quick and dirty way to tell if a path
points to a directory?


man 2 stat

Cheers,

-j

--
Jeffrey Goldberghttp://www.goldmark.org/jeff/

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: testing for directory

2007-04-29 Thread Don Hinton
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  or 
Institute for Software Integrated Systems (ISIS), Vanderbilt University
tel: 615.480.5667 or 615.870.9728


pgpCl51TDL7hA.pgp
Description: PGP signature


Re: testing for directory

2007-04-29 Thread Roland Smith
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?

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
-- 
R.F.Smith   http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)


pgp82o0Z9g4ES.pgp
Description: PGP signature