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

Comparing ray/src/common/getpath.c (file contents):
Revision 2.14 by schorsch, Thu Jul 17 09:21:29 2003 UTC vs.
Revision 2.15 by schorsch, Mon Oct 27 10:19:31 2003 UTC

# Line 11 | Line 11 | static const char      RCSid[] = "$Id$";
11  
12   #include  <string.h>
13   #include  <ctype.h>
14 #ifdef   RHAS_GETPWNAM
15  #include  <pwd.h>
16  #include  <sys/types.h>
17 #endif
14  
15   #include  "paths.h"
16   #include  "rtio.h"
# Line 33 | Line 29 | register char  *searchpath,
29   int  mode
30   )
31   {
36 #ifdef   RHAS_GETPWNAM
37        struct passwd  *pwent;
38 #endif
32          static char  pname[PATH_MAX];
33 +        char uname[512];
34          register char  *cp;
35 +        int i;
36  
37          if (fname == NULL) { return(NULL); }
38  
39          pname[0] = '\0';                /* check for full specification */
40  
41 <        if (ISABS(fname)) { /* Can't use CASEDIRSEP below on Windows */
41 >        if (ISABS(fname)) { /* absolute path */
42                  strncpy(pname, fname, sizeof(pname)-1);
43          } else {
44                  switch (*fname) {
50                        /* XXX This doesn't work on Windows */
51                        /* CASEDIRSEP: */                       /* relative to root */
45                          case '.':                               /* relative to cwd */
46                                  strncpy(pname, fname, sizeof(pname)-1);
47                                  break;
48                          case '~':                               /* relative to home directory */
49                                  fname++;
50 <                                if (*fname == '\0' || ISDIRSEP(*fname)) {       /* ours */
51 <                                        if ((cp = getenv("HOME")) == NULL)
59 < #ifdef _WIN32  /* Windows sometimes uses a different var name */
60 <                                                if ((cp = getenv("HOMEDIR")) == NULL)
61 < #endif
62 <                                                        return(NULL);
63 <                                        strncpy(pname, cp, sizeof(pname)-1);
64 <                                        strncat(pname, fname, sizeof(pname)-strlen(pname)-1);
65 <                                        break;
66 <                                }
67 < #ifdef RHAS_GETPWNAM
68 <                                /* XXX Should we request our own home directory from the
69 <                                   XXX system as well if the above fails? */
70 <                                /* XXX In any case, we need do the same thing on Windows... */
71 <                                cp = pname;                                     /* user */
72 <                                do
50 >                                cp = uname;
51 >                                for (i=0;i<sizeof(uname)&&*fname!='\0'&&!ISDIRSEP(*fname);i++)
52                                          *cp++ = *fname++;
74                                while (*fname && !ISDIRSEP(*fname));
53                                  *cp = '\0';
54 <                                if ((pwent = getpwnam(pname)) == NULL)
55 <                                        return(NULL);
78 <                                strncpy(pname, pwent->pw_dir, sizeof(pname)-1);
54 >                                cp = gethomedir(uname, pname, sizeof(pname));
55 >                                if(cp == NULL) return NULL;
56                                  strncat(pname, fname, sizeof(pname)-strlen(pname)-1);
57                                  break;
81 #endif
58                  }
59          }
60          if (pname[0])           /* got it, check access if search requested */
# Line 166 | Line 142 | int main()
142          printf(fmt,  "/",        "PATH", "W_OK", fp);
143          fp = getpath("~", getenv("PATH"), F_OK);
144          printf(fmt,  "~",        "PATH", "F_OK", fp);
145 <        printf("Undefining HOME and HOMEDIR\n");
145 >        printf("Undefining HOME and HOMEPATH\n");
146          unsetenv("HOME");
147 <        unsetenv("HOMEDIR");
147 >        unsetenv("HOMEPATH");
148          fp = getpath("~", getenv("PATH"), F_OK);
149          printf(fmt,  "~",        "PATH", "F_OK", fp);
150 < #ifndef RHAS_GETPWNAM
151 <        fp = getpath("~lp", getenv("PATH"), F_OK);
176 <        printf(fmt, "~lp",         "PATH", "F_OK", fp);
177 < #endif
150 >        fp = getpath("~lp/blah", getenv("PATH"), F_OK);
151 >        printf(fmt, "~lp/blah",         "PATH", "F_OK", fp);
152   }
153   #endif
154  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines