--- ray/src/common/getpath.c 2003/07/03 20:59:00 2.13 +++ ray/src/common/getpath.c 2004/02/12 18:55:50 2.17 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: getpath.c,v 2.13 2003/07/03 20:59:00 schorsch Exp $"; +static const char RCSid[] = "$Id: getpath.c,v 2.17 2004/02/12 18:55:50 greg Exp $"; #endif /* * getpath.c - function to search for file in a list of directories @@ -11,15 +11,11 @@ static const char RCSid[] = "$Id: getpath.c,v 2.13 200 #include #include -#ifdef RHAS_GETPWNAM - #include - #include -#endif +#include "rtio.h" #include "paths.h" - #ifdef _WIN32 static char * core_getpath /* wrapped below: expand fname, return full path */ @@ -33,52 +29,32 @@ register char *searchpath, int mode ) { -#ifdef RHAS_GETPWNAM - struct passwd *pwent; -#endif static char pname[PATH_MAX]; + char uname[512]; register char *cp; + int i; if (fname == NULL) { return(NULL); } pname[0] = '\0'; /* check for full specification */ - if (ISABS(fname)) { /* Can't use CASEDIRSEP below on Windows */ + if (ISABS(fname)) { /* absolute path */ strncpy(pname, fname, sizeof(pname)-1); } else { switch (*fname) { - /* XXX This doesn't work on Windows */ - /* CASEDIRSEP: */ /* relative to root */ case '.': /* relative to cwd */ strncpy(pname, fname, sizeof(pname)-1); break; case '~': /* relative to home directory */ fname++; - if (*fname == '\0' || ISDIRSEP(*fname)) { /* ours */ - if ((cp = getenv("HOME")) == NULL) -#ifdef _WIN32 /* Windows sometimes uses a different var name */ - if ((cp = getenv("HOMEDIR")) == NULL) -#endif - return(NULL); - strncpy(pname, cp, sizeof(pname)-1); - strncat(pname, fname, sizeof(pname)-strlen(pname)-1); - break; - } -#ifdef RHAS_GETPWNAM - /* XXX Should we request our own home directory from the - XXX system as well if the above fails? */ - /* XXX In any case, we need do the same thing on Windows... */ - cp = pname; /* user */ - do + cp = uname; + for (i=0;ipw_dir, sizeof(pname)-1); + cp = gethomedir(uname, pname, sizeof(pname)); + if(cp == NULL) return NULL; strncat(pname, fname, sizeof(pname)-strlen(pname)-1); break; -#endif } } if (pname[0]) /* got it, check access if search requested */ @@ -166,15 +142,13 @@ int main() printf(fmt, "/", "PATH", "W_OK", fp); fp = getpath("~", getenv("PATH"), F_OK); printf(fmt, "~", "PATH", "F_OK", fp); - printf("Undefining HOME and HOMEDIR\n"); + printf("Undefining HOME and HOMEPATH\n"); unsetenv("HOME"); - unsetenv("HOMEDIR"); + unsetenv("HOMEPATH"); fp = getpath("~", getenv("PATH"), F_OK); printf(fmt, "~", "PATH", "F_OK", fp); -#ifndef RHAS_GETPWNAM - fp = getpath("~lp", getenv("PATH"), F_OK); - printf(fmt, "~lp", "PATH", "F_OK", fp); -#endif + fp = getpath("~lp/blah", getenv("PATH"), F_OK); + printf(fmt, "~lp/blah", "PATH", "F_OK", fp); } #endif