--- ray/src/common/getpath.c 1992/03/25 10:57:29 2.2 +++ ray/src/common/getpath.c 2003/02/25 02:47:21 2.10 @@ -1,19 +1,22 @@ -/* Copyright (c) 1991 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 */ -#define NULL 0 +#include "copyright.h" -#include +#include "standard.h" -extern char *strcpy(), *strcat(), *getenv(); +#include "paths.h" + +#ifndef NIX +#include extern struct passwd *getpwnam(); +#endif char * @@ -22,38 +25,45 @@ 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 '/': /* 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 == '/') { /* 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 != '/'); + 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); @@ -62,14 +72,10 @@ int mode; /* check search path */ do { cp = pname; - while (*searchpath && (*cp = *searchpath++) != ':') - if (*cp == '\\') { /* escape */ - if (*searchpath) - *cp++ = *searchpath++; - } else - cp++; - if (cp > pname && cp[-1] != '/') - *cp++ = '/'; + while (*searchpath && (*cp = *searchpath++) != PATHSEP) + cp++; + if (cp > pname && !ISDIRSEP(cp[-1])) + *cp++ = DIRSEP; strcpy(cp, fname); if (access(pname, mode) == 0) /* file accessable? */ return(pname);