Path: utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!wuarchive!udel!princeton!phoenix!pfalstad From: pfalstad@phoenix.Princeton.EDU (Paul John Falstad) Newsgroups: comp.unix.questions Subject: Re: /bin/pwd Message-ID: <2497@idunno.Princeton.EDU> Date: 13 Sep 90 23:36:21 GMT References: <2488@idunno.Princeton.EDU> <13851@smoke.BRL.MIL> Sender: news@idunno.Princeton.EDU Organization: Princeton University, Princeton, New Jersey Lines: 17 In article <13851@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes: >In article <2488@idunno.Princeton.EDU> pfalstad@phoenix.Princeton.EDU (Paul John Falstad) writes: >>Can anyone tell me how /bin/pwd works? I thought it was a trivial >>program until I tried to write my own without getcwd(3). getcwd is not >>a system call, so it must be possible. The way I think it works is >>quite complicated, so I thought there would be an easier way. >No, on most systems there is no easier way than the obvious one of >seeing where a succession of ".."s gets you. That was what I considered "the easy way." But how do you do that? For example, how do you find out the name of "."? You could find out its inode, and then check the previous directory to see which name matches its inode; but that only works until you get to the root of the filesystem your directory is mounted in (I don't mean "/"). What then? Do you have to check /etc/mtab? I think there should be more race prejudice. LESS race prejudice.