--- ray/src/common/getpath.c 1992/06/16 13:29:35 2.3 +++ ray/src/common/getpath.c 1993/08/26 10:14:32 2.8 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -8,61 +8,61 @@ static char SCCSid[] = "$SunId$ LBL"; * getpath.c - function to search for file in a list of directories */ -#define NULL 0 +#include "standard.h" -#include +#include "paths.h" -#ifndef DIRSEP -#define DIRSEP '/' +#ifndef NIX +#include +extern struct passwd *getpwnam(); #endif -#ifndef PATHSEP -#define PATHSEP ':' -#endif -extern char *strcpy(), *strcat(), *getenv(); -extern struct passwd *getpwnam(); - char * getpath(fname, searchpath, mode) /* expand fname, return full path */ register char *fname; register char *searchpath; int mode; { - static char pname[256]; +#ifndef NIX struct passwd *pwent; +#endif + static char pname[MAXPATH]; register char *cp; if (fname == NULL) return(NULL); + pname[0] = '\0'; /* check for full specification */ switch (*fname) { - case DIRSEP: /* relative to root */ + CASEDIRSEP: /* relative to root */ case '.': /* relative to cwd */ strcpy(pname, fname); - return(pname); + break; #ifndef NIX case '~': /* relative to home directory */ fname++; - if (*fname == '\0' || *fname == DIRSEP) { /* ours */ + if (*fname == '\0' || ISDIRSEP(*fname)) { /* ours */ if ((cp = getenv("HOME")) == NULL) return(NULL); strcpy(pname, cp); strcat(pname, fname); - return(pname); + break; } cp = pname; /* user */ do *cp++ = *fname++; - while (*fname && *fname != DIRSEP); + while (*fname && !ISDIRSEP(*fname)); *cp = '\0'; if ((pwent = getpwnam(pname)) == NULL) 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); @@ -73,7 +73,7 @@ int mode; cp = pname; while (*searchpath && (*cp = *searchpath++) != PATHSEP) cp++; - if (cp > pname && cp[-1] != DIRSEP) + if (cp > pname && !ISDIRSEP(cp[-1])) *cp++ = DIRSEP; strcpy(cp, fname); if (access(pname, mode) == 0) /* file accessable? */