Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!cs.utexas.edu!natinst!rpp386!jfh From: jfh@rpp386.cactus.org (John F. Haugh II) Newsgroups: comp.unix.wizards Subject: Re: Anything faster than stat(S)? need to determine File or Dir Message-ID: <17264@rpp386.cactus.org> Date: 10 Nov 89 15:29:30 GMT References: <152@norsat.UUCP> <2586@unisoft.UUCP> <15769@bloom-beacon.MIT.EDU> Reply-To: jfh@rpp386.cactus.org (John F. Haugh II) Organization: Lone Star Cafe and BBS Service Lines: 45 In article <15769@bloom-beacon.MIT.EDU> jik@athena.mit.edu (Jonathan I. Kamens) writes: >In article <2586@unisoft.UUCP> greywolf@unisoft.UUCP (The Grey Wolf) writes: >>I think, IMHO, you're better off going with stat(). > > Yup, I think so too. That's how I do it in the code I've written. Just for the sake of disagreeing, what about other system calls that are able to distinguish between a file being a directory or not? The error return entries for access(1) tell me something useful - A component of the path prefix is not a directory. [ENOTDIR] The named file does not exist. [ENOENT] How about code like this - #include 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. 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. Ain't perfect either, but maybe better? -- John F. Haugh II +-Things you didn't want to know:------ VoiceNet: (512) 832-8832 Data: -8835 | The real meaning of EMACS is ... InterNet: jfh@rpp386.cactus.org | ... EMACS makes a computer slow. UUCPNet: {texbell|bigtex}!rpp386!jfh +--<><--<><--<><--<><--<><--<><--<><---