Why use pwd(1) for getpwd(3C)? (Re: Why use find?)

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Thu Oct 11 13:09:19 AEST 1990


In article <1990Oct11.012643.11274 at diku.dk> kimcm at diku.dk (Kim Christian Madsen) writes:
> >In article <1990Oct9.122813.1329 at cbnews.att.com> jbr0 at cbnews.att.com (joseph.a.brownlee) writes:
> >  [ why is getpwd() implemented as `pwd` in System V? ]
> >Because there's no getwd() system call to have the kernel do the job.
> >Unless you have some sort of privileges, you won't be able to figure
> >out the current directory when any higher directory is unreadable.
> That's maybe the indirect reason, the rest is because of sloppy AT&T
> programmers, that figured that there was no reason to copy code from
> pwd(1) into the getpwd(3C) routine.

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. This is not an ``indirect'' reason.

> SYSVR4 is supposed to eliminate this
> idiotic behaviour of getpwd(3C),

POSIX has the system call (why'd they have to use a different name?), so
all modern UNIX versions have a fast getpwd().

---Dan



More information about the Comp.unix.programmer mailing list