Date: Sun, 29 Apr 2007 16:46:02 -0500 From: Don Hinton <don.hinton@vanderbilt.edu> To: freebsd-questions@freebsd.org Cc: Roland Smith <rsmith@xs4all.nl>, Robert Huff <roberthuff@rcn.com>, questions@freebsd.org Subject: Re: testing for directory Message-ID: <200704291646.07563.don.hinton@vanderbilt.edu> In-Reply-To: <20070429205848.GA15950@slackbox.xs4all.nl> References: <17973.654.765099.201323@jerusalem.litteratus.org> <20070429205848.GA15950@slackbox.xs4all.nl>
next in thread | previous in thread | raw e-mail | index | archive | help
--nextPart21813582.2lYLT75PCR Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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= ,=20 and errno =3D EINVAL, it's not a directory. (man getdirentries for more in= fo) 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 =2D-=20 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 --nextPart21813582.2lYLT75PCR Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (FreeBSD) iD8DBQBGNRIf0U0xbM5cLs0RAnQBAKC5LGPgUUQ1o6XL1ByIMQ1IsvN0PACfUBot ioS01EMZ8h4dQEtSWmj1Ihc= =B60B -----END PGP SIGNATURE----- --nextPart21813582.2lYLT75PCR--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200704291646.07563.don.hinton>