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

Tim Wright tim at delluk.uucp
Sat Oct 13 02:21:39 AEST 1990


In <23012:Oct1019:12:2790 at kramden.acf.nyu.edu> brnstnd at kramden.acf.nyu.edu (Dan Bernstein) 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.

>---Dan

Well I can't speak for all System V's but all the ones I have used don't
have /bin/pwd suid anyway so that's no excuse. It would still be *massively*
more efficient to do the work pwd does in a library call (i.e. stat back
up the tree), than it is to fork and exec another command ! It just looks
like people were very lazy (it couldn't have been that difficult to copy
the pwd code to the library).

$ cd junk
$ chmod 700 junk
$ chown somebody_else junk
$ pwd
pwd: cannot stat .!

Yuk !

Tim
--
Tim Wright, Dell Computer Corp. (UK) | Email address
Dell Computer Corp. (UK), Bracknell  | Domain: tim at dell.co.uk
Tel: +44-344-860456                  | Uucp: ...!ukc!delluk!tim
"What's the problem? You've got an IQ of six thousand, haven't you?"



More information about the Comp.unix.programmer mailing list