How to write a current directory finder?
Felix Lee
flee at shire.cs.psu.edu
Mon Apr 3 06:03:00 AEST 1989
Doing a "trace" shows that getwd() does not chdir().
Here is speculation on Sun's getwd() after trying to implement my own
and watching a "trace".
* It caches its result. Repeated calls to getwd() just make two
stat() calls. Trying to time the performance of getwd() by putting it
in a loop is meaningless. This is the big win.
* It uses /tmp/.getwd to figure out where it is when it crosses a
mount point. This is a minor gain. In my version of getwd(), I
stat'ed around to find the mount point; commenting out the stat()
calls saved about .005s system time (on a Sun4 running SunOS4.0).
Any other differences in algorithm (using fstat() instead of stat(),
using chdir(), etc.) have little effect on performance.
--
Felix Lee flee at shire.cs.psu.edu *!psuvax1!shire!flee
More information about the Comp.unix.wizards
mailing list