ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/gethomedir.c
(Generate patch)

Comparing ray/src/common/gethomedir.c (file contents):
Revision 1.2 by schorsch, Sun Mar 6 01:13:17 2016 UTC vs.
Revision 1.3 by greg, Sun Jul 21 16:48:34 2019 UTC

# Line 23 | Line 23 | gethomedir(char *uname, char *path, int plen)
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;
# Line 57 | Line 55 | gethomedir(char *uname, char *path, int plen)
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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines