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.4 by greg, Mon Jul 13 16:33:19 1992 UTC vs.
Revision 2.10 by greg, Tue Feb 25 02:47:21 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  getpath.c - function to search for file in a list of directories
6 + *
7 + *  External symbols declared in standard.h
8   */
9  
10 < #define  NULL           0
10 > #include "copyright.h"
11  
12 < #ifndef  NIX
14 < #include  <pwd.h>
15 < #endif
12 > #include  "standard.h"
13  
14 < #ifndef DIRSEP
18 < #define DIRSEP          '/'
19 < #endif
20 < #ifndef PATHSEP
21 < #define PATHSEP         ':'
22 < #endif
14 > #include  "paths.h"
15  
16 < extern char  *strcpy(), *strcat(), *getenv();
16 > #ifndef  NIX
17 > #include  <pwd.h>
18   extern struct passwd  *getpwnam();
19 + #endif
20  
21  
22   char *
# Line 31 | Line 25 | register char  *fname;
25   register char  *searchpath;
26   int  mode;
27   {
28 < #ifndef  NIX
28 > #ifndef  NIX
29          struct passwd  *pwent;
30   #endif
31 <        static char  pname[256];
31 >        static char  pname[MAXPATH];
32          register char  *cp;
33  
34          if (fname == NULL)
35                  return(NULL);
36  
37 +        pname[0] = '\0';                /* check for full specification */
38          switch (*fname) {
39 <        case DIRSEP:                            /* relative to root */
39 >        CASEDIRSEP:                             /* relative to root */
40          case '.':                               /* relative to cwd */
41                  strcpy(pname, fname);
42 <                return(pname);
42 >                break;
43   #ifndef NIX
44          case '~':                               /* relative to home directory */
45                  fname++;
46 <                if (*fname == '\0' || *fname == DIRSEP) {       /* ours */
46 >                if (*fname == '\0' || ISDIRSEP(*fname)) {       /* ours */
47                          if ((cp = getenv("HOME")) == NULL)
48                                  return(NULL);
49                          strcpy(pname, cp);
50                          strcat(pname, fname);
51 <                        return(pname);
51 >                        break;
52                  }
53                  cp = pname;                                     /* user */
54                  do
55                          *cp++ = *fname++;
56 <                while (*fname && *fname != DIRSEP);
56 >                while (*fname && !ISDIRSEP(*fname));
57                  *cp = '\0';
58                  if ((pwent = getpwnam(pname)) == NULL)
59                          return(NULL);
60                  strcpy(pname, pwent->pw_dir);
61                  strcat(pname, fname);
62 <                return(pname);
62 >                break;
63   #endif
64          }
65 +        if (pname[0])           /* got it, check access if search requested */
66 +                return(searchpath==NULL||access(pname,mode)==0 ? pname : NULL);
67  
68          if (searchpath == NULL) {                       /* don't search */
69                  strcpy(pname, fname);
# Line 77 | Line 74 | int  mode;
74                  cp = pname;
75                  while (*searchpath && (*cp = *searchpath++) != PATHSEP)
76                          cp++;
77 <                if (cp > pname && cp[-1] != DIRSEP)
77 >                if (cp > pname && !ISDIRSEP(cp[-1]))
78                          *cp++ = DIRSEP;
79                  strcpy(cp, fname);
80                  if (access(pname, mode) == 0)           /* file accessable? */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines