9 |
|
#include "copyright.h" |
10 |
|
|
11 |
|
#include <stdlib.h> |
12 |
– |
#include <string.h> |
12 |
|
|
13 |
|
#include "rtio.h" |
14 |
|
|
15 |
< |
#ifdef _WIN32 |
15 |
> |
#if defined(_WIN32) || defined(_WIN64) |
16 |
|
|
17 |
|
char * |
18 |
|
gethomedir(char *uname, char *path, int plen) |
22 |
|
if (uname == NULL || *uname == '\0') { /* ours */ |
23 |
|
/* pretend we're on unix first (eg. for Cygwin) */ |
24 |
|
if ((cp = getenv("HOME")) != NULL) { |
25 |
< |
strncpy(path, cp, plen); |
27 |
< |
path[plen-1] = '\0'; |
25 |
> |
strlcpy(path, cp, plen); |
26 |
|
return path; |
27 |
|
} |
28 |
|
/* now let's see what Windows thinks */ |
29 |
|
if ((cd = getenv("HOMEDRIVE")) != NULL |
30 |
|
&& (cp = getenv("HOMEPATH")) != NULL) { |
31 |
< |
strncpy(path, cd, plen); |
32 |
< |
strncat(path, cp, plen-2); |
35 |
< |
path[plen-1] = '\0'; |
31 |
> |
strlcpy(path, cd, plen); |
32 |
> |
strlcat(path, cp, plen); |
33 |
|
return path; |
34 |
|
} |
35 |
|
return NULL; |
38 |
|
return NULL; |
39 |
|
} |
40 |
|
|
41 |
< |
#else /* _WIN32 */ |
41 |
> |
#else /* _WIN32 || _WIN64 */ |
42 |
|
|
43 |
|
|
44 |
|
#include <unistd.h> |
54 |
|
|
55 |
|
if (uname == NULL || *uname == '\0') { /* ours */ |
56 |
|
if ((cp = getenv("HOME")) != NULL) { |
57 |
< |
strncpy(path, cp, plen); |
61 |
< |
path[plen-1] = '\0'; |
57 |
> |
strlcpy(path, cp, plen); |
58 |
|
return path; |
59 |
|
} |
60 |
|
uid = getuid(); |
61 |
|
if ((pwent = getpwuid(uid)) == NULL) |
62 |
|
return(NULL); /* we don't exist ?!? */ |
63 |
< |
strncpy(path, pwent->pw_dir, plen); |
68 |
< |
path[plen-1] = '\0'; |
63 |
> |
strlcpy(path, pwent->pw_dir, plen); |
64 |
|
return path; |
65 |
|
} |
66 |
|
/* someone else */ |
67 |
|
if ((pwent = getpwnam(uname)) == NULL) |
68 |
|
return(NULL); /* no such user */ |
69 |
|
|
70 |
< |
strncpy(path, pwent->pw_dir, plen); |
76 |
< |
path[plen-1] = '\0'; |
70 |
> |
strlcpy(path, pwent->pw_dir, plen); |
71 |
|
return path; |
72 |
|
} |
73 |
|
|
74 |
< |
#endif /* _WIN32 */ |
74 |
> |
#endif /* _WIN32 || _WIN64 */ |
75 |
|
|