--- ray/src/common/getpath.c 1992/09/08 10:04:34 2.6 +++ ray/src/common/getpath.c 2003/02/25 02:47:21 2.10 @@ -1,32 +1,31 @@ -/* Copyright (c) 1992 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: getpath.c,v 2.10 2003/02/25 02:47:21 greg Exp $"; #endif - /* * getpath.c - function to search for file in a list of directories + * + * External symbols declared in standard.h */ -#include "paths.h" +#include "copyright.h" -#define NULL 0 +#include "standard.h" -#ifndef NIX +#include "paths.h" + +#ifndef NIX #include extern struct passwd *getpwnam(); #endif -extern char *strcpy(), *strcat(), *getenv(); - char * getpath(fname, searchpath, mode) /* expand fname, return full path */ register char *fname; register char *searchpath; int mode; { -#ifndef NIX +#ifndef NIX struct passwd *pwent; #endif static char pname[MAXPATH]; @@ -35,11 +34,12 @@ int mode; if (fname == NULL) return(NULL); + pname[0] = '\0'; /* check for full specification */ switch (*fname) { CASEDIRSEP: /* relative to root */ case '.': /* relative to cwd */ strcpy(pname, fname); - return(pname); + break; #ifndef NIX case '~': /* relative to home directory */ fname++; @@ -48,7 +48,7 @@ int mode; return(NULL); strcpy(pname, cp); strcat(pname, fname); - return(pname); + break; } cp = pname; /* user */ do @@ -59,9 +59,11 @@ int mode; return(NULL); strcpy(pname, pwent->pw_dir); strcat(pname, fname); - return(pname); + break; #endif } + if (pname[0]) /* got it, check access if search requested */ + return(searchpath==NULL||access(pname,mode)==0 ? pname : NULL); if (searchpath == NULL) { /* don't search */ strcpy(pname, fname);