[BACK]Return to which.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / which

Diff for /src/usr.bin/which/which.c between version 1.24 and 1.25

version 1.24, 2016/01/14 22:00:53 version 1.25, 2016/01/14 22:02:13
Line 98 
Line 98 
 findprog(char *prog, char *path, int progmode, int allmatches)  findprog(char *prog, char *path, int progmode, int allmatches)
 {  {
         char *p, filename[PATH_MAX];          char *p, filename[PATH_MAX];
         int proglen, plen, rval = 0;          int len, rval = 0;
         struct stat sbuf;          struct stat sbuf;
         char *pathcpy;          char *pathcpy;
   
Line 118 
Line 118 
                 err(1, "strdup");                  err(1, "strdup");
         pathcpy = path;          pathcpy = path;
   
         proglen = strlen(prog);  
         while ((p = strsep(&pathcpy, ":")) != NULL) {          while ((p = strsep(&pathcpy, ":")) != NULL) {
                 if (*p == '\0')                  if (*p == '\0')
                         p = ".";                          p = ".";
   
                 plen = strlen(p);                  len = strlen(p);
                 while (plen > 0 && p[plen-1] == '/')                  while (len > 0 && p[len-1] == '/')
                         p[--plen] = '\0';       /* strip trailing '/' */                          p[--len] = '\0';        /* strip trailing '/' */
   
                 if (plen + 1 + proglen >= sizeof(filename)) {                  len = snprintf(filename, sizeof(filename), "%s/%s", p, prog);
                   if (len < 0 || len >= sizeof(filename)) {
                         warnc(ENAMETOOLONG, "%s/%s", p, prog);                          warnc(ENAMETOOLONG, "%s/%s", p, prog);
                         free(path);                          free(path);
                         return (0);                          return (0);
                 }                  }
   
                 snprintf(filename, sizeof(filename), "%s/%s", p, prog);  
                 if ((stat(filename, &sbuf) == 0) && S_ISREG(sbuf.st_mode) &&                  if ((stat(filename, &sbuf) == 0) && S_ISREG(sbuf.st_mode) &&
                     access(filename, X_OK) == 0) {                      access(filename, X_OK) == 0) {
                         (void)puts(filename);                          (void)puts(filename);

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25