ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/gethomedir.c
Revision: 1.4
Committed: Sat Dec 28 18:05:14 2019 UTC (4 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, rad5R3, HEAD
Changes since 1.3: +1 -2 lines
Log Message:
Removed redundant include files

File Contents

# User Rev Content
1 schorsch 1.1 #ifndef lint
2 greg 1.4 static const char RCSid[] = "$Id: gethomedir.c,v 1.3 2019/07/21 16:48:34 greg Exp $";
3 schorsch 1.1 #endif
4     /*
5     * gethomedir.c - search for a users home directory
6     *
7     */
8    
9     #include "copyright.h"
10    
11     #include <stdlib.h>
12    
13     #include "rtio.h"
14    
15 schorsch 1.2 #if defined(_WIN32) || defined(_WIN64)
16 schorsch 1.1
17     char *
18     gethomedir(char *uname, char *path, int plen)
19     {
20     char *cd, *cp;
21    
22     if (uname == NULL || *uname == '\0') { /* ours */
23     /* pretend we're on unix first (eg. for Cygwin) */
24     if ((cp = getenv("HOME")) != NULL) {
25 greg 1.3 strlcpy(path, cp, plen);
26 schorsch 1.1 return path;
27     }
28     /* now let's see what Windows thinks */
29     if ((cd = getenv("HOMEDRIVE")) != NULL
30     && (cp = getenv("HOMEPATH")) != NULL) {
31 greg 1.3 strlcpy(path, cd, plen);
32     strlcat(path, cp, plen);
33 schorsch 1.1 return path;
34     }
35     return NULL;
36     }
37     /* No idea how to find the home directory of another user */
38     return NULL;
39     }
40    
41 schorsch 1.2 #else /* _WIN32 || _WIN64 */
42 schorsch 1.1
43    
44     #include <unistd.h>
45     #include <pwd.h>
46     #include <sys/types.h>
47    
48     char *
49     gethomedir(char *uname, char *path, int plen)
50     {
51     struct passwd *pwent;
52     uid_t uid;
53     char *cp;
54    
55     if (uname == NULL || *uname == '\0') { /* ours */
56     if ((cp = getenv("HOME")) != NULL) {
57 greg 1.3 strlcpy(path, cp, plen);
58 schorsch 1.1 return path;
59     }
60     uid = getuid();
61     if ((pwent = getpwuid(uid)) == NULL)
62     return(NULL); /* we don't exist ?!? */
63 greg 1.3 strlcpy(path, pwent->pw_dir, plen);
64 schorsch 1.1 return path;
65     }
66     /* someone else */
67     if ((pwent = getpwnam(uname)) == NULL)
68     return(NULL); /* no such user */
69    
70 greg 1.3 strlcpy(path, pwent->pw_dir, plen);
71 schorsch 1.1 return path;
72     }
73    
74 schorsch 1.2 #endif /* _WIN32 || _WIN64 */
75 schorsch 1.1