--- ray/src/common/getpath.c 2013/12/19 16:38:12 2.18 +++ ray/src/common/getpath.c 2021/11/22 18:23:56 2.22 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: getpath.c,v 2.18 2013/12/19 16:38:12 greg Exp $"; +static const char RCSid[] = "$Id: getpath.c,v 2.22 2021/11/22 18:23:56 greg Exp $"; #endif /* * getpath.c - function to search for file in a list of directories @@ -9,14 +9,13 @@ static const char RCSid[] = "$Id: getpath.c,v 2.18 201 #include "copyright.h" -#include #include #include "rtio.h" #include "paths.h" -#ifdef _WIN32 +#if defined(_WIN32) || defined(_WIN64) static char * core_getpath /* wrapped below: expand fname, return full path */ #else @@ -34,46 +33,47 @@ 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 */ - strncpy(pname, fname, sizeof(pname)-1); + if (ISABS(fname)) { /* absolute path */ + strlcpy(pname, fname, sizeof(pname)); } else { switch (*fname) { - case '.': /* relative to cwd */ - strncpy(pname, fname, sizeof(pname)-1); + 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 pname && !ISDIRSEP(cp[-1])) { + while (*searchpath && (*cp = *searchpath++) != PATHSEP) + cp += (cp-pname < sizeof(pname)-2); + if (cp > pname && !ISDIRSEP(cp[-1])) *cp++ = DIRSEP; - } - strncpy(cp, fname, sizeof(pname)-strlen(pname)-1); + *cp = '\0'; + strlcat(pname, fname, sizeof(pname)); if (access(pname, mode) == 0) /* file accessable? */ return(pname); } while (*searchpath); @@ -82,7 +82,7 @@ getpath /* expand fname, return full path */ } -#ifdef _WIN32 +#if defined(_WIN32) || defined(_WIN64) /* This is a wrapper around the above, "emulating" access mode X_OK, which is not supported on Windows. If we see X_OK and the filename has no extension, then we'll remove @@ -101,13 +101,13 @@ getpath( /* expand fname, return full path */ char *cp; char fname[PATH_MAX]; - if (ffname == NULL) - return(NULL); + if (!fname | (fname == pname)) + return(fname); /* 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); }