--- ray/src/common/gethomedir.c 2003/10/27 10:20:58 1.1 +++ ray/src/common/gethomedir.c 2019/12/28 18:05:14 1.4 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: gethomedir.c,v 1.1 2003/10/27 10:20:58 schorsch Exp $"; +static const char RCSid[] = "$Id: gethomedir.c,v 1.4 2019/12/28 18:05:14 greg Exp $"; #endif /* * gethomedir.c - search for a users home directory @@ -9,11 +9,10 @@ static const char RCSid[] = "$Id: gethomedir.c,v 1.1 2 #include "copyright.h" #include -#include #include "rtio.h" -#ifdef _WIN32 +#if defined(_WIN32) || defined(_WIN64) char * gethomedir(char *uname, char *path, int plen) @@ -23,16 +22,14 @@ gethomedir(char *uname, char *path, int plen) if (uname == NULL || *uname == '\0') { /* ours */ /* pretend we're on unix first (eg. for Cygwin) */ if ((cp = getenv("HOME")) != NULL) { - strncpy(path, cp, plen); - path[plen-1] = '\0'; + strlcpy(path, cp, plen); return path; } /* now let's see what Windows thinks */ if ((cd = getenv("HOMEDRIVE")) != NULL && (cp = getenv("HOMEPATH")) != NULL) { - strncpy(path, cd, plen); - strncat(path, cp, plen-2); - path[plen-1] = '\0'; + strlcpy(path, cd, plen); + strlcat(path, cp, plen); return path; } return NULL; @@ -41,7 +38,7 @@ gethomedir(char *uname, char *path, int plen) return NULL; } -#else /* _WIN32 */ +#else /* _WIN32 || _WIN64 */ #include @@ -57,25 +54,22 @@ gethomedir(char *uname, char *path, int plen) if (uname == NULL || *uname == '\0') { /* ours */ if ((cp = getenv("HOME")) != NULL) { - strncpy(path, cp, plen); - path[plen-1] = '\0'; + strlcpy(path, cp, plen); return path; } uid = getuid(); if ((pwent = getpwuid(uid)) == NULL) return(NULL); /* we don't exist ?!? */ - strncpy(path, pwent->pw_dir, plen); - path[plen-1] = '\0'; + strlcpy(path, pwent->pw_dir, plen); return path; } /* someone else */ if ((pwent = getpwnam(uname)) == NULL) return(NULL); /* no such user */ - strncpy(path, pwent->pw_dir, plen); - path[plen-1] = '\0'; + strlcpy(path, pwent->pw_dir, plen); return path; } -#endif /* _WIN32 */ +#endif /* _WIN32 || _WIN64 */