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.16 by schorsch, Fri Nov 14 17:22:06 2003 UTC vs.
Revision 2.20 by greg, Sun Jul 21 16:48:34 2019 UTC

# Line 4 | Line 4 | static const char      RCSid[] = "$Id$";
4   /*
5   *  getpath.c - function to search for file in a list of directories
6   *
7 < *  External symbols declared in standard.h
7 > *  External symbols declared in rtio.h
8   */
9  
10   #include "copyright.h"
# Line 13 | Line 13 | static const char      RCSid[] = "$Id$";
13   #include  <ctype.h>
14  
15   #include  "rtio.h"
16 + #include  "paths.h"
17  
18  
19 < #ifdef _WIN32
19 > #if defined(_WIN32) || defined(_WIN64)
20   static char *
21   core_getpath    /* wrapped below: expand fname, return full path */
22   #else
# Line 23 | Line 24 | char *
24   getpath /* expand fname, return full path */
25   #endif
26   (
27 < register char  *fname,
28 < register char  *searchpath,
29 < int  mode
27 >        char  *fname,
28 >        char  *searchpath,
29 >        int  mode
30   )
31   {
32          static char  pname[PATH_MAX];
33          char uname[512];
34 <        register char  *cp;
34 >        char  *cp;
35          int i;
36  
37          if (fname == NULL) { return(NULL); }
# Line 38 | Line 39 | int  mode
39          pname[0] = '\0';                /* check for full specification */
40  
41          if (ISABS(fname)) { /* absolute path */
42 <                strncpy(pname, fname, sizeof(pname)-1);
42 >                strlcpy(pname, fname, sizeof(pname));
43          } else {
44                  switch (*fname) {
45 <                        case '.':                               /* relative to cwd */
46 <                                strncpy(pname, fname, sizeof(pname)-1);
45 >                        case '.':               /* relative to cwd */
46 >                                strlcpy(pname, fname, sizeof(pname));
47                                  break;
48 <                        case '~':                               /* relative to home directory */
48 >                        case '~':               /* relative to home directory */
49                                  fname++;
50                                  cp = uname;
51 <                                for (i=0;i<sizeof(uname)&&*fname!='\0'&&!ISDIRSEP(*fname);i++)
51 >                                for (i = 0; i < sizeof(uname) && *fname
52 >                                                && !ISDIRSEP(*fname); i++)
53                                          *cp++ = *fname++;
54                                  *cp = '\0';
55                                  cp = gethomedir(uname, pname, sizeof(pname));
56                                  if(cp == NULL) return NULL;
57 <                                strncat(pname, fname, sizeof(pname)-strlen(pname)-1);
57 >                                strlcat(pname, fname, sizeof(pname));
58                                  break;
59                  }
60          }
61          if (pname[0])           /* got it, check access if search requested */
62 <                return(searchpath==NULL||access(pname,mode)==0 ? pname : NULL);
62 >                return(!searchpath || access(pname,mode)==0 ? pname : NULL);
63  
64 <        if (searchpath == NULL) {                       /* don't search */
65 <                strncpy(pname, fname, sizeof(pname)-1);
64 >        if (!searchpath) {                      /* no search */
65 >                strlcpy(pname, fname, sizeof(pname));
66                  return(pname);
67          }
68          /* check search path */
69          do {
70                  cp = pname;
71 <                while (*searchpath && (*cp = *searchpath++) != PATHSEP) {
72 <                        cp++;
73 <                }
72 <                if (cp > pname && !ISDIRSEP(cp[-1])) {
71 >                while (*searchpath && (*cp = *searchpath++) != PATHSEP)
72 >                        cp += (cp-pname < sizeof(pname)-2);
73 >                if (cp > pname && !ISDIRSEP(cp[-1]))
74                          *cp++ = DIRSEP;
75 <                }
76 <                strncpy(cp, fname, sizeof(pname)-strlen(pname)-1);
75 >                *cp = '\0';
76 >                strlcat(pname, fname, sizeof(pname));
77                  if (access(pname, mode) == 0)           /* file accessable? */
78                          return(pname);
79          } while (*searchpath);
# Line 81 | Line 82 | int  mode
82   }
83  
84  
85 < #ifdef _WIN32
85 > #if defined(_WIN32) || defined(_WIN64)
86   /* This is a wrapper around the above, "emulating" access mode X_OK,
87     which is not supported on Windows.
88     If we see X_OK and the filename has no extension, then we'll remove
# Line 92 | Line 93 | int  mode
93   */
94   char *
95   getpath(        /* expand fname, return full path */
96 < register char  *ffname,
97 < register char  *searchpath,
98 < int  mode
96 >        char  *ffname,
97 >        char  *searchpath,
98 >        int  mode
99   )
100   {
101 <        register char  *cp;
101 >        char  *cp;
102          char fname[PATH_MAX];
103  
104          if (ffname == NULL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines