--- ray/src/common/getpath.c 2019/07/21 16:48:34 2.20 +++ ray/src/common/getpath.c 2025/06/07 05:09:45 2.24 @@ -1,18 +1,16 @@ #ifndef lint -static const char RCSid[] = "$Id: getpath.c,v 2.20 2019/07/21 16:48:34 greg Exp $"; +static const char RCSid[] = "$Id: getpath.c,v 2.24 2025/06/07 05:09:45 greg Exp $"; #endif /* * getpath.c - function to search for file in a list of directories * - * External symbols declared in rtio.h + * External symbols declared in paths.h */ #include "copyright.h" -#include #include -#include "rtio.h" #include "paths.h" @@ -34,18 +32,19 @@ getpath /* expand fname, return full path */ char *cp; int i; - if (fname == NULL) { return(NULL); } + if (!fname | (fname == pname)) + return(fname); pname[0] = '\0'; /* check for full specification */ - if (ISABS(fname)) { /* absolute path */ + if (ISABS(fname)) { /* absolute path */ strlcpy(pname, fname, sizeof(pname)); } else { switch (*fname) { - case '.': /* relative to cwd */ + case '.': /* relative to cwd */ strlcpy(pname, fname, sizeof(pname)); break; - case '~': /* relative to home directory */ + case '~': /* relative to home directory */ fname++; cp = uname; for (i = 0; i < sizeof(uname) && *fname @@ -61,7 +60,7 @@ getpath /* expand fname, return full path */ if (pname[0]) /* got it, check access if search requested */ return(!searchpath || access(pname,mode)==0 ? pname : NULL); - if (!searchpath) { /* no search */ + if (!searchpath) { /* no search? */ strlcpy(pname, fname, sizeof(pname)); return(pname); } @@ -101,13 +100,13 @@ getpath( /* expand fname, return full path */ char *cp; char fname[PATH_MAX]; - if (ffname == NULL) - return(NULL); + if (!ffname | (ffname == fname)) + return(ffname); /* if we have a dot in the string, we assume there is a file name extension present */ /* XXX We'd better test for .exe/.bat/.etc explicitly */ - if (!(mode & X_OK) || (strrchr(ffname, '.') != NULL)) { + if (!(mode & X_OK) || strchr(ffname, '.') > ffname) { return core_getpath(ffname, searchpath, mode); }