Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!gatech!udel!princeton!phoenix.Princeton.EDU!subbarao From: subbarao@phoenix.Princeton.EDU (Kartik Subbarao) Newsgroups: comp.unix.programmer Subject: Re: getting the current working directory Message-ID: <5305@idunno.Princeton.EDU> Date: 13 Jan 91 22:55:00 GMT References: <42380@ut-emx.uucp> Sender: news@idunno.Princeton.EDU Distribution: usa Lines: 68 In article denap@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 */ 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@ut-emx.uucp> Sender: Followup-To: Distribution: usa Organization: Keywords: In article denap@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 */ 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@silvertone.Princeton.EDU (NeXT mail) -| SUBBARAO@PUCC.BITNET - Bitnet