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

Diff for /src/usr.bin/mg/fileio.c between version 1.17 and 1.18

version 1.17, 2001/05/24 10:19:51 version 1.18, 2001/07/06 13:32:45
Line 498 
Line 498 
         LIST            *last;          LIST            *last;
         struct filelist *current;          struct filelist *current;
         char            prefixx[NFILEN + 1];          char            prefixx[NFILEN + 1];
         struct stat     statbuf;  
         char            statname[NFILEN + 2];  
   
         /*          /*
          * We need three different strings: dir - the name of the directory           * We need three different strings: dir - the name of the directory
Line 574 
Line 572 
         last = NULL;          last = NULL;
   
         while ((dent = readdir(dirp)) != NULL) {          while ((dent = readdir(dirp)) != NULL) {
                   int isdir;
   
                 if (dent->d_namlen < len || memcmp(cp, dent->d_name, len) != 0)                  if (dent->d_namlen < len || memcmp(cp, dent->d_name, len) != 0)
                         continue;                          continue;
   
                 current = (struct filelist *) malloc(sizeof(struct filelist));                  isdir = 0;
                   if (dent->d_type == DT_DIR) {
                           isdir = 1;
                   } else if (dent->d_type == DT_LNK ||
                               dent->d_type == DT_UNKNOWN) {
                           struct stat     statbuf;
                           char            statname[NFILEN + 2];
   
                           statbuf.st_mode = 0;
                           if (snprintf(statname, sizeof(statname), "%s/%s",
                               dir, dent->d_name) > sizeof(statname) - 1) {
                                   continue;
                           }
                           if (stat(statname, &statbuf) < 0)
                                   continue;
                           if (statbuf.st_mode & S_IFDIR)
                                   isdir = 1;
                   }
   
                   current = malloc(sizeof(struct filelist));
                 if (current == NULL)                  if (current == NULL)
                         break;                          break;
   
                 if (snprintf(current->fl_name, sizeof(current->fl_name),                  if (snprintf(current->fl_name, sizeof(current->fl_name),
                     "%s%s%s", prefixx, dent->d_name, dent->d_type == DT_DIR?                      "%s%s%s", prefixx, dent->d_name, isdir ? "/" : "")
                     "/" : "") >= sizeof(current->fl_name)) {                      >= sizeof(current->fl_name)) {
                         free(current);                          free(current);
                         continue;                          continue;
                 }                  }
                 current->fl_l.l_next = last;                  current->fl_l.l_next = last;
                 current->fl_l.l_name = current->fl_name;                  current->fl_l.l_name = current->fl_name;
                 last = (LIST *) current;                  last = (LIST *) current;
                 if (dent->d_type != DT_UNKNOWN)  
                         continue;  
   
                 statbuf.st_mode = 0;  
                 if (snprintf(statname, sizeof(statname), "%s/%s",  
                     dir, dent->d_name) > sizeof(statname) - 1) {  
                         continue;  
                 }  
                 if (stat(statname, &statbuf) < 0)  
                         continue;  
                 if (statbuf.st_mode & S_IFDIR)  
                         strcat(current->fl_name, "/");  
         }          }
         closedir(dirp);          closedir(dirp);
   

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18