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

Diff for /src/usr.bin/diff/diff.c between version 1.27 and 1.28

version 1.27, 2003/07/09 00:07:44 version 1.28, 2003/07/09 00:39:25
Line 30 
Line 30 
 #include <err.h>  #include <err.h>
 #include <errno.h>  #include <errno.h>
 #include <getopt.h>  #include <getopt.h>
   #include <signal.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdarg.h>  #include <stdarg.h>
Line 120 
Line 121 
                         break;                          break;
                 case 'l':                  case 'l':
                         lflag = 1;                          lflag = 1;
                           signal(SIGPIPE, SIG_IGN);
                         break;                          break;
                 case 'N':                  case 'N':
                         Nflag = 1;                          Nflag = 1;
Line 183 
Line 185 
                 fstat(STDIN_FILENO, &stb1);                  fstat(STDIN_FILENO, &stb1);
                 gotstdin = 1;                  gotstdin = 1;
         } else if (stat(argv[0], &stb1) != 0)          } else if (stat(argv[0], &stb1) != 0)
                 error("%s", argv[0]);                  err(2, "%s", argv[0]);
         if (strcmp(argv[1], "-") == 0) {          if (strcmp(argv[1], "-") == 0) {
                 fstat(STDIN_FILENO, &stb2);                  fstat(STDIN_FILENO, &stb2);
                 gotstdin = 1;                  gotstdin = 1;
         } else if (stat(argv[1], &stb2) != 0)          } else if (stat(argv[1], &stb2) != 0)
                 error("%s", argv[1]);                  err(2, "%s", argv[1]);
         if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode)))          if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode)))
                 errorx("can't compare - to a directory");                  errx(2, "can't compare - to a directory");
         set_argstr(oargv, argv);          set_argstr(oargv, argv);
         if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) {          if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) {
                 if (format == D_IFDEF)                  if (format == D_IFDEF)
                         errorx("-D option not supported with directories");                          errx(2, "-D option not supported with directories");
                 diffdir(argv[0], argv[1]);                  diffdir(argv[0], argv[1]);
         } else {          } else {
                   if (S_ISDIR(stb1.st_mode)) {
                           argv[0] = splice(argv[0], argv[1]);
                           if (stat(argv[0], &stb1) < 0)
                                   err(2, "%s", argv[0]);
                   }
                   if (S_ISDIR(stb2.st_mode)) {
                           argv[1] = splice(argv[1], argv[0]);
                           if (stat(argv[1], &stb2) < 0)
                                   err(2, "%s", argv[1]);
                   }
                 print_status(diffreg(argv[0], argv[1], 0), argv[0], argv[1],                  print_status(diffreg(argv[0], argv[1], 0), argv[0], argv[1],
                     NULL);                      NULL);
         }          }
         exit(status);          exit(status);
 }  }
   
 void  
 quit(int signo)  
 {  
         if (tempfiles[0] != NULL)  
                 unlink(tempfiles[0]);  
         if (tempfiles[1] != NULL)  
                 unlink(tempfiles[1]);  
         _exit(status);  
 }  
   
 void *  void *
 emalloc(size_t n)  emalloc(size_t n)
 {  {
         void *p;          void *p;
   
         if ((p = malloc(n)) == NULL)          if ((p = malloc(n)) == NULL)
                 error(NULL);                  err(2, NULL);
         return (p);          return (p);
 }  }
   
Line 229 
Line 231 
         void *q;          void *q;
   
         if ((q = realloc(p, n)) == NULL)          if ((q = realloc(p, n)) == NULL)
                 error(NULL);                  err(2, NULL);
         return (q);          return (q);
 }  }
   
Line 244 
Line 246 
         va_end(ap);          va_end(ap);
   
         if (len == -1)          if (len == -1)
                 error(NULL);                  err(2, NULL);
         return(len);          return(len);
 }  }
   
 __dead void  
 error(const char *fmt, ...)  
 {  
         va_list ap;  
         int sverrno = errno;  
   
         if (tempfiles[0] != NULL)  
                 unlink(tempfiles[0]);  
         if (tempfiles[1] != NULL)  
                 unlink(tempfiles[1]);  
         errno = sverrno;  
         va_start(ap, fmt);  
         verr(2, fmt, ap);  
         va_end(ap);  
 }  
   
 __dead void  
 errorx(const char *fmt, ...)  
 {  
         va_list ap;  
   
         if (tempfiles[0] != NULL)  
                 unlink(tempfiles[0]);  
         if (tempfiles[1] != NULL)  
                 unlink(tempfiles[1]);  
         va_start(ap, fmt);  
         verrx(2, fmt, ap);  
         va_end(ap);  
 }  
   
 void  void
 set_argstr(char **av, char **ave)  set_argstr(char **av, char **ave)
 {  {
Line 308 
Line 280 
         if (strcmp(file, "-") == 0)          if (strcmp(file, "-") == 0)
                 fp = stdin;                  fp = stdin;
         else if ((fp = fopen(file, "r")) == NULL)          else if ((fp = fopen(file, "r")) == NULL)
                 error("%s", file);                  err(2, "%s", file);
         while ((buf = fgetln(fp, &len)) != NULL) {          while ((buf = fgetln(fp, &len)) != NULL) {
                 if (buf[len - 1] == '\n')                  if (buf[len - 1] == '\n')
                         len--;                          len--;
Line 361 
Line 333 
                         printf("Files %s%s and %s%s are identical\n",                          printf("Files %s%s and %s%s are identical\n",
                             path1, entry ? entry : "",                              path1, entry ? entry : "",
                             path2, entry ? entry : "");                              path2, entry ? entry : "");
                   break;
           case D_MISMATCH:
                   printf("File %s/%s is a directory but file %s/%s is not\n",
                       path1, entry ? entry : "", path2, entry ? entry : "");
                 break;                  break;
         }          }
 }  }

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.28