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

Diff for /src/usr.bin/lndir/lndir.c between version 1.18 and 1.19

version 1.18, 2006/11/15 22:23:11 version 1.19, 2010/08/22 21:25:37
Line 61 
Line 61 
   
 extern char *__progname;  extern char *__progname;
   
 int silent = 0;                 /* -silent */  int silent;                     /* -silent */
 int ignore_links = 0;           /* -ignorelinks */  int ignore_links;               /* -ignorelinks */
   
 char *rcurdir;  char *rcurdir;
 char *curdir;  char *curdir;
Line 77 
Line 77 
         struct except *next;          struct except *next;
 };  };
   
 struct except *exceptions = (struct except *)NULL;  struct except *exceptions;
   
 int  int
 main(int argc, char *argv[])  main(int argc, char *argv[])
Line 146 
Line 146 
                         memmove(s + 1, ns, strlen(ns) + 1);                          memmove(s + 1, ns, strlen(ns) + 1);
                 }                  }
         }          }
         return(strcmp(lname, rname) == 0);          return (strcmp(lname, rname) == 0);
 }  }
   
 void  void
Line 154 
Line 154 
 {  {
         struct except *new;          struct except *new;
   
         new = (struct except *)malloc(sizeof(struct except));          new = malloc(sizeof(struct except));
         if (new == (struct except *)NULL)          if (new == NULL)
                 err(1, NULL);                  err(1, NULL);
         new->name = strdup(name);          new->name = strdup(name);
         if (new->name == (char *)NULL)          if (new->name == NULL)
                 err(1, NULL);                  err(1, NULL);
   
         new->next = exceptions;          new->next = exceptions;
Line 179 
Line 179 
 int  int
 dodir(char *fn, struct stat *fs, struct stat *ts, int rel)  dodir(char *fn, struct stat *fs, struct stat *ts, int rel)
 {  {
         char buf[MAXPATHLEN + 1], symbuf[MAXPATHLEN + 1], basesym[MAXPATHLEN + 1];          char buf[MAXPATHLEN + 1], symbuf[MAXPATHLEN + 1];
           char basesym[MAXPATHLEN + 1];
         int n_dirs, symlen, basesymlen = -1;          int n_dirs, symlen, basesymlen = -1;
         struct stat sb, sc;          struct stat sb, sc;
         struct except *cur;          struct except *cur;
Line 226 
Line 227 
                                 /* directory */                                  /* directory */
                                 n_dirs--;                                  n_dirs--;
                                 if (dp->d_name[0] == '.' &&                                  if (dp->d_name[0] == '.' &&
                                     (dp->d_name[1] == '\0' || (dp->d_name[1] == '.' &&                                      (dp->d_name[1] == '\0' ||
                                       (dp->d_name[1] == '.' &&
                                     dp->d_name[2] == '\0')))                                      dp->d_name[2] == '\0')))
                                         continue;                                          continue;
                                 if (!strcmp(dp->d_name, "RCS"))                                  if (!strcmp(dp->d_name, "RCS"))
Line 242 
Line 244 
                                 curdir = silent ? buf : NULL;                                  curdir = silent ? buf : NULL;
                                 if (!silent)                                  if (!silent)
                                         printf("%s:\n", buf);                                          printf("%s:\n", buf);
                                 if (stat(dp->d_name, &sc) < 0 && errno == ENOENT) {                                  if (stat(dp->d_name, &sc) < 0 &&
                                       errno == ENOENT) {
                                         if (mkdir(dp->d_name, 0777) < 0 ||                                          if (mkdir(dp->d_name, 0777) < 0 ||
                                             stat(dp->d_name, &sc) < 0) {                                              stat(dp->d_name, &sc) < 0) {
                                                 warn("%s", dp->d_name);                                                  warn("%s", dp->d_name);
Line 253 
Line 256 
                                 if (readlink(dp->d_name, symbuf,                                  if (readlink(dp->d_name, symbuf,
                                     sizeof(symbuf) - 1) >= 0) {                                      sizeof(symbuf) - 1) >= 0) {
                                         fprintf(stderr,                                          fprintf(stderr,
                                             "%s: is a link instead of a directory\n",                                              "%s: is a link instead of a "
                                               "directory\n",
                                             dp->d_name);                                              dp->d_name);
                                         curdir = rcurdir = ocurdir;                                          curdir = rcurdir = ocurdir;
                                         continue;                                          continue;
Line 279 
Line 283 
                 /*                  /*
                  * The option to ignore links exists mostly because                   * The option to ignore links exists mostly because
                  * checking for them slows us down by 10-20%.                   * checking for them slows us down by 10-20%.
                  * But it is off by default because this really is a useful check.                   * But it is off by default because this is a useful check.
                  */                   */
                 if (!ignore_links) {                  if (!ignore_links) {
                         /* see if the file in the base tree was a symlink */                          /* see if the file in the base tree was a symlink */
                         basesymlen = readlink(buf, basesym, sizeof(basesym) - 1);                          basesymlen = readlink(buf, basesym,
                               sizeof(basesym) - 1);
                         if (basesymlen >= 0)                          if (basesymlen >= 0)
                                 basesym[basesymlen] = '\0';                                  basesym[basesymlen] = '\0';
                 }                  }
Line 293 
Line 298 
                          * Link exists in new tree.  Print message if                           * Link exists in new tree.  Print message if
                          * it doesn't match.                           * it doesn't match.
                          */                           */
                         if (!equivalent(basesymlen>=0 ? basesym : buf, symbuf))                          if (!equivalent(basesymlen >= 0 ? basesym : buf,
                               symbuf))
                                 fprintf(stderr,"%s: %s\n", dp->d_name, symbuf);                                  fprintf(stderr,"%s: %s\n", dp->d_name, symbuf);
                 } else {                  } else {
                         if (symlink(basesymlen>=0 ? basesym : buf, dp->d_name) < 0)                          if (symlink(basesymlen >= 0 ? basesym : buf,
                               dp->d_name) < 0)
                                 warn("%s", dp->d_name);                                  warn("%s", dp->d_name);
                 }                  }
 next:  next:
Line 304 
Line 311 
         }          }
   
         closedir(df);          closedir(df);
         return(0);          return (0);
 }  }
   
 void  void
 usage(void)  usage(void)
 {  {
         (void)fprintf(stderr, "usage: %s [-is] [-e exceptfile] fromdir [todir]\n",          fprintf(stderr, "usage: %s [-is] [-e exceptfile] fromdir [todir]\n",
             __progname);              __progname);
         exit(1);          exit(1);
 }  }

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