--- ray/src/common/getpath.c 2016/03/06 01:13:17 2.19 +++ ray/src/common/getpath.c 2019/07/21 16:48:34 2.20 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: getpath.c,v 2.19 2016/03/06 01:13:17 schorsch Exp $"; +static const char RCSid[] = "$Id: getpath.c,v 2.20 2019/07/21 16:48:34 greg Exp $"; #endif /* * getpath.c - function to search for file in a list of directories @@ -39,41 +39,41 @@ getpath /* expand fname, return full path */ pname[0] = '\0'; /* check for full specification */ if (ISABS(fname)) { /* absolute path */ - strncpy(pname, fname, sizeof(pname)-1); + 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);