Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!cs.utexas.edu!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.unix.wizards Subject: Re: Anything faster than stat(S)? need to determine File or Dir Message-ID: <1989Nov11.154312.6675@virtech.uucp> Date: 11 Nov 89 15:43:12 GMT References: <152@norsat.UUCP> <2586@unisoft.UUCP> <15769@bloom-beacon.MIT.EDU> <17264@rpp386.cactus.org> Organization: Virtual Technologies Inc. Lines: 32 In article <17264@rpp386.cactus.org>, jfh@rpp386.cactus.org (John F. Haugh II) writes: > Just for the sake of disagreeing, what about other system calls that > are able to distinguish between a file being a directory or not? > > How about code like this - > [sample of using access() deleted] > > 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. So you want to replace a single call to stat() with multiple calls to access(). That doesn't make any sense since the major overhead to both the stat and access system calls is that the path must be traversed and since you are calling access twice, you have to traverse the path twice. stat() is the most effecient mechanism that can be used to obtain information about a file system entry since it just looks up an inode and copies the data to the user's data area. If you are stating all entries in a directory on a very heavily loaded system you could probably get some performance gain by chdir()ing to the directory and then stating the entities with just the basename (thereby not having to parse the path every time). This shouldn't have much of an effect on a lightly loaded system due to caching. -- +-----------------------------------------------------------------------+ | Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 ! | Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 | +-----------------------------------------------------------------------+