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.13 by schorsch, Thu Jul 3 20:59:00 2003 UTC vs.
Revision 2.16 by schorsch, Fri Nov 14 17:22:06 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"
15 > #include  "rtio.h"
16  
17  
22
18   #ifdef _WIN32
19   static char *
20   core_getpath    /* wrapped below: expand fname, return full path */
# Line 33 | Line 28 | register char  *searchpath,
28   int  mode
29   )
30   {
36 #ifdef   RHAS_GETPWNAM
37        struct passwd  *pwent;
38 #endif
31          static char  pname[PATH_MAX];
32 +        char uname[512];
33          register char  *cp;
34 +        int i;
35  
36          if (fname == NULL) { return(NULL); }
37  
38          pname[0] = '\0';                /* check for full specification */
39  
40 <        if (ISABS(fname)) { /* Can't use CASEDIRSEP below on Windows */
40 >        if (ISABS(fname)) { /* absolute path */
41                  strncpy(pname, fname, sizeof(pname)-1);
42          } else {
43                  switch (*fname) {
50                        /* XXX This doesn't work on Windows */
51                        /* CASEDIRSEP: */                       /* relative to root */
44                          case '.':                               /* relative to cwd */
45                                  strncpy(pname, fname, sizeof(pname)-1);
46                                  break;
47                          case '~':                               /* relative to home directory */
48                                  fname++;
49 <                                if (*fname == '\0' || ISDIRSEP(*fname)) {       /* ours */
50 <                                        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
49 >                                cp = uname;
50 >                                for (i=0;i<sizeof(uname)&&*fname!='\0'&&!ISDIRSEP(*fname);i++)
51                                          *cp++ = *fname++;
74                                while (*fname && !ISDIRSEP(*fname));
52                                  *cp = '\0';
53 <                                if ((pwent = getpwnam(pname)) == NULL)
54 <                                        return(NULL);
78 <                                strncpy(pname, pwent->pw_dir, sizeof(pname)-1);
53 >                                cp = gethomedir(uname, pname, sizeof(pname));
54 >                                if(cp == NULL) return NULL;
55                                  strncat(pname, fname, sizeof(pname)-strlen(pname)-1);
56                                  break;
81 #endif
57                  }
58          }
59          if (pname[0])           /* got it, check access if search requested */
# Line 166 | Line 141 | int main()
141          printf(fmt,  "/",        "PATH", "W_OK", fp);
142          fp = getpath("~", getenv("PATH"), F_OK);
143          printf(fmt,  "~",        "PATH", "F_OK", fp);
144 <        printf("Undefining HOME and HOMEDIR\n");
144 >        printf("Undefining HOME and HOMEPATH\n");
145          unsetenv("HOME");
146 <        unsetenv("HOMEDIR");
146 >        unsetenv("HOMEPATH");
147          fp = getpath("~", getenv("PATH"), F_OK);
148          printf(fmt,  "~",        "PATH", "F_OK", fp);
149 < #ifndef RHAS_GETPWNAM
150 <        fp = getpath("~lp", getenv("PATH"), F_OK);
176 <        printf(fmt, "~lp",         "PATH", "F_OK", fp);
177 < #endif
149 >        fp = getpath("~lp/blah", getenv("PATH"), F_OK);
150 >        printf(fmt, "~lp/blah",         "PATH", "F_OK", fp);
151   }
152   #endif
153  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines