Inside PWD

Conor P. Cahill cpcahil at virtech.UUCP
Mon Oct 16 10:39:48 AEST 1989


In article <166 at volvo.vd.volvo.se>, peter at vd.volvo.se (Peter Hkansson) writes:
> not by doing 'system pwd' or something like that but by a system call.
> To use a library call would mean to use a system call en the end
> (all library routines uses system calls in the end ??),so that would
> not answer my question.


If I understand your question, you want to determine your present working 
directory from within a program.  The only mechanism you can use is to 
get the inode of the current directory (.) and look up that inode in the
current directories parent (..) and so on and so forth, properly handling
the crossing of mount points and stopping at the root of all evil.

The system V solution is to call the getcwd (i think) library function 
which calls the pwd program and saves the output in a string, a pointer
to which is returned to the calling function.

The bsd solution is to write the routine into the library call and to
have the program call the library call.

BTW - there is no system call to do this because the system doesn't know
where you are (other than the inode of your current directory).

-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+



More information about the Comp.unix.wizards mailing list