Need subroutine to return full file path name
Steve Roseman
lusgr at vax1.cc.lehigh.edu
Sat Feb 24 02:39:53 AEST 1990
In article <10071.25e01a55 at vax1.cc.lehigh.edu>, lusgr at 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 at VAX1.CC.Lehigh.EDU
More information about the Comp.unix.aix
mailing list