getting the current working directory

Kartik Subbarao subbarao at phoenix.Princeton.EDU
Mon Jan 14 09:55:00 AEST 1991


In article <DENAP.91Jan11134939 at alta.sw.stratus.com> denap at alta.sw.stratus.com (Tom DeNapoli) writes:
>Along the same lines... 
>
>Has anyone got anything that will return the absolute pathname of
>an open file to a process?  
>
>Process A has file ./dir1/dir2/foo open and he wants the absolute
>path to the file as in /usr/local/stuff/dir1/dir2.  
>

A way to do this is to chdir() to the directory of the file (i.e.
dir1/dir2) and then do a getcwd() to find out where absolutely where you
are, like this:

/* # include <sys/param.h> */
    
    char fullpath[MAXPATHLEN];
    chdir("dir1/dir2"); 
    getcwd(fullpath, MAXPATHLEN);
    printf("Full pathname is %s\n", fullpath);


			-Kartik



Newsgroups: comp.unix.programmer
Subject: Re: getting the current working directory
Summary: 
Expires: 
References: <42380 at ut-emx.uucp> <DENAP.91Jan11134939 at alta.sw.stratus.com>
Sender: 
Followup-To: 
Distribution: usa
Organization:  
Keywords: 

In article <DENAP.91Jan11134939 at alta.sw.stratus.com> denap at alta.sw.stratus.com (Tom DeNapoli) writes:
>Along the same lines... 
>
>Has anyone got anything that will return the absolute pathname of
>an open file to a process?  
>
>Process A has file ./dir1/dir2/foo open and he wants the absolute
>path to the file as in /usr/local/stuff/dir1/dir2.  
>

A way to do this is to chdir() to the directory of the file (i.e.
dir1/dir2) and then do a getcwd() to find out where absolutely where you
are, like this:

/* # include <sys/param.h> */
    
    char fullpath[MAXPATHLEN];
    chdir("dir1/dir2"); 
    getcwd(fullpath, MAXPATHLEN);
    printf("Full pathname is %s\n", fullpath);


			-Kartik



--
internet# ls -alR | grep *.c
subbarao@{phoenix or gauguin}.Princeton.EDU -|Internet
kartik at silvertone.Princeton.EDU (NeXT mail)       -|	
SUBBARAO at PUCC.BITNET			          - Bitnet



More information about the Comp.unix.programmer mailing list