23 |
|
if (uname == NULL || *uname == '\0') { /* ours */ |
24 |
|
/* pretend we're on unix first (eg. for Cygwin) */ |
25 |
|
if ((cp = getenv("HOME")) != NULL) { |
26 |
< |
strncpy(path, cp, plen); |
27 |
< |
path[plen-1] = '\0'; |
26 |
> |
strlcpy(path, cp, plen); |
27 |
|
return path; |
28 |
|
} |
29 |
|
/* now let's see what Windows thinks */ |
30 |
|
if ((cd = getenv("HOMEDRIVE")) != NULL |
31 |
|
&& (cp = getenv("HOMEPATH")) != NULL) { |
32 |
< |
strncpy(path, cd, plen); |
33 |
< |
strncat(path, cp, plen-2); |
35 |
< |
path[plen-1] = '\0'; |
32 |
> |
strlcpy(path, cd, plen); |
33 |
> |
strlcat(path, cp, plen); |
34 |
|
return path; |
35 |
|
} |
36 |
|
return NULL; |
55 |
|
|
56 |
|
if (uname == NULL || *uname == '\0') { /* ours */ |
57 |
|
if ((cp = getenv("HOME")) != NULL) { |
58 |
< |
strncpy(path, cp, plen); |
61 |
< |
path[plen-1] = '\0'; |
58 |
> |
strlcpy(path, cp, plen); |
59 |
|
return path; |
60 |
|
} |
61 |
|
uid = getuid(); |
62 |
|
if ((pwent = getpwuid(uid)) == NULL) |
63 |
|
return(NULL); /* we don't exist ?!? */ |
64 |
< |
strncpy(path, pwent->pw_dir, plen); |
68 |
< |
path[plen-1] = '\0'; |
64 |
> |
strlcpy(path, pwent->pw_dir, plen); |
65 |
|
return path; |
66 |
|
} |
67 |
|
/* someone else */ |
68 |
|
if ((pwent = getpwnam(uname)) == NULL) |
69 |
|
return(NULL); /* no such user */ |
70 |
|
|
71 |
< |
strncpy(path, pwent->pw_dir, plen); |
76 |
< |
path[plen-1] = '\0'; |
71 |
> |
strlcpy(path, pwent->pw_dir, plen); |
72 |
|
return path; |
73 |
|
} |
74 |
|
|