lusgr@vax1.cc.lehigh.edu (Steve Roseman) (02/20/90)
I need to find out the full path name of a file from a full or partial name entered by the user, so other users can access the file (assuming proper permissions, etc.) For example, a user currently in /u/mydir/sub: input: test.c output: /u/mydir/sub/test.c input: /u/frog output: /u/frog input: ../filename output: /u/mydir/filename SUN OS has a routine realpath(3), but that doesn't do very much good with AIX 2.2.1. I have looked through the AIX OS Tech Ref manual, but can't find anything. If anyone has a lead, or a routine, I would appreciate not having to write it myself. Thanks, Steve ------------------------------------------------------------------------- Steve Roseman Lehigh University Computing Center LUSGR@VAX1.CC.Lehigh.EDU
lusgr@vax1.cc.lehigh.edu (Steve Roseman) (02/23/90)
In article <10071.25e01a55@vax1.cc.lehigh.edu>, lusgr@vax1.cc.lehigh.edu (Steve Roseman) writes: > I need to find out the full path name of a file from a full or partial > name entered by the user, so other users can access the file (assuming > proper permissions, etc.) > > For example, a user currently in /u/mydir/sub: > > input: test.c output: /u/mydir/sub/test.c > input: /u/frog output: /u/frog > input: ../filename output: /u/mydir/filename > > ... Thanks to the several respondents who had suggestions. Nothing, unfortunately, was workable, so I finally kludged up my own routine. 1. Separate the dir part from the file name (via strrchr). 2. If only a file name, append the name to the current directory. Done. 3. Else, chdir to the directory part, do a getcwd, and chdir back to the original place. That gives me a full directory, and I add in the file name. Voila. Tacky, but... The performance may not be the greatest (getcwd works by piping the output of a pwd command), and error checking lacking a bit, but it will not be used heavily, and it got me past a bothersome hurdle. Thanks again for the suggestions, Steve (Wow, 2 non-RIOS articles in a row...) ------------------------------------------------------------------------- Steve Roseman Lehigh University Computing Center LUSGR@VAX1.CC.Lehigh.EDU