Why use pwd(1) for getpwd(3C)? (Re: Why use find?)
Dave Jenks
jetfuel at csusac.csus.edu
Thu Oct 11 14:44:35 AEST 1990
In article <28623:Oct1103:09:1990 at kramden.acf.nyu.edu> brnstnd at kramden.acf.nyu.edu (Dan Bernstein) writes:
>They weren't sloppy. There certainly was a reason not to copy code into
>getpwd(). If getpwd() doesn't invoke any system calls and doesn't invoke
>any setuid programs, then it may not be able to figure out the current
>directory. That would be ungood.
Actually, pwd(1) has no better chance of being able to figure out the
current directory than getpwd(3) could, since pwd follows the
directory from "." to "/" using each directory's ".." entry.
The obvious advantage of using getpwd(3) is that it need not create a
new process, etc. which does the same thing. Just having it all in a
library routine (even the EXACT same code) would be faster and less
prone to possible (however unlikely) errors.
An interesting side note to all this - pwd won't work in a directory
which doesn't contain the "." and ".." entries, or part of the path
does not. I guess you could keep someone from knowing where the
program chdir()ed to...
--
=======================================================================
"Pro is to con, as progress is to Congress..."
>>-@@-> Dave Jenks {uunet | ucbvax!ucdavis}!csusac!jetfuel
=======================================================================
More information about the Comp.unix.programmer
mailing list