[comp.unix.programmer] Why does getpwd

jbw@bucsf.bu.edu (Joe Wells) (10/17/90)

In article <3554@skye.ed.ac.uk> richard@aiai.ed.ac.uk (Richard Tobin) writes:

   Why does getpwd() have to chdir()?

In most Unixes, there's a kernel limit of 1024 characters in a pathname.
If your current directory were located deep enough in the filesystem,
getcwd() couldn't make it all the way up to the root without chdir()-ing.
Of course, you understand how unlikely this is, but it is necessary for
the algorithm to be correct.

-- 
Joe Wells <jbw@bu.edu>

richard@aiai.ed.ac.uk (Richard Tobin) (10/19/90)

In article <JBW.90Oct16175441@bucsf.bu.edu> jbw@bucsf.bu.edu (Joe Wells) writes:
>In most Unixes, there's a kernel limit of 1024 characters in a pathname.
>If your current directory were located deep enough in the filesystem,
>getcwd() couldn't make it all the way up to the root without chdir()-ing.

In this case, the returned pathname is unlikely to be very useful!

-- Richard
-- 
Richard Tobin,                       JANET: R.Tobin@uk.ac.ed             
AI Applications Institute,           ARPA:  R.Tobin%uk.ac.ed@nsfnet-relay.ac.uk
Edinburgh University.                UUCP:  ...!ukc!ed.ac.uk!R.Tobin