Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!mcsun!hp4nl!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.wizards Subject: of course! (was: Anything faster than stat(S)? [...]) Message-ID: <4526@ski.cs.vu.nl> Date: 13 Nov 89 22:32:29 GMT References: <152@norsat.UUCP> <2586@unisoft.UUCP> <15769@bloom-beacon.MIT.EDU> <17264@rpp386.cactus.org> Reply-To: maart@cs.vu.nl (Maarten Litmaath) Organization: VU Informatica, Amsterdam Lines: 39 In article <17264@rpp386.cactus.org> jfh@rpp386.cactus.org (John F. Haugh II) writes: \... \ isadir (char *path) \ { \ char dir[PATH_MAX]; \ \ if (access (path, 0)) \ return 0; \ \ strcpy (dir, path); \ strcat (dir, "/x"); \ \ errno = 0; \ access (dir, 0); \ \ return errno == 0 || errno == ENOENT; \ } \ \We know all of the initial path exists because of the first access() \call. Can you say `race condition'? \And with the second access() call we can discover if the \last component of `path' isn't a directory since errno would be ENOTDIR \rather than ENOENT. isadir(char *path) { char dir[PATH_MAX]; strcpy(dir, path); strcat(dir, "/."); return access(dir, 0); } -- "Richard Sexton is actually an AI program (or Construct, if you will) running on some AT&T (R) 3B" (Richard Brosseau) | maart@cs.vu.nl, mcsun!botter!maart