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

Diff for /src/usr.bin/patch/inp.c between version 1.21 and 1.22

version 1.21, 2003/07/31 14:10:21 version 1.22, 2003/08/01 20:30:48
Line 53 
Line 53 
                 i_womp = NULL;                  i_womp = NULL;
                 i_ptr = NULL;                  i_ptr = NULL;
         } else {          } else {
                 using_plan_a = TRUE;    /* maybe the next one is smaller */                  using_plan_a = true;    /* maybe the next one is smaller */
                 close(tifd);                  close(tifd);
                 tifd = -1;                  tifd = -1;
                 free(tibuf[0]);                  free(tibuf[0]);
Line 88 
Line 88 
         struct stat     filestat;          struct stat     filestat;
   
         if (filename == NULL || *filename == '\0')          if (filename == NULL || *filename == '\0')
                 return FALSE;                  return false;
   
         statfailed = stat(filename, &filestat);          statfailed = stat(filename, &filestat);
         if (statfailed && ok_to_create_file) {          if (statfailed && ok_to_create_file) {
Line 101 
Line 101 
                  * to normal patch behavior as possible                   * to normal patch behavior as possible
                  */                   */
                 if (check_only)                  if (check_only)
                         return TRUE;                          return true;
                 makedirs(filename, TRUE);                  makedirs(filename, true);
                 close(creat(filename, 0666));                  close(creat(filename, 0666));
                 statfailed = stat(filename, &filestat);                  statfailed = stat(filename, &filestat);
         }          }
Line 178 
Line 178 
         i_size = filestat.st_size;          i_size = filestat.st_size;
         if (out_of_mem) {          if (out_of_mem) {
                 set_hunkmax();  /* make sure dynamic arrays are allocated */                  set_hunkmax();  /* make sure dynamic arrays are allocated */
                 out_of_mem = FALSE;                  out_of_mem = false;
                 return FALSE;   /* force plan b because plan a bombed */                  return false;   /* force plan b because plan a bombed */
         }          }
         if (i_size > SIZE_MAX - 2)          if (i_size > SIZE_MAX - 2)
                 fatal("block too large to allocate");                  fatal("block too large to allocate");
         i_womp = malloc((size_t)(i_size + 2));          i_womp = malloc((size_t)(i_size + 2));
         if (i_womp == NULL)          if (i_womp == NULL)
                 return FALSE;                  return false;
         if ((ifd = open(filename, O_RDONLY)) < 0)          if ((ifd = open(filename, O_RDONLY)) < 0)
                 pfatal("can't open file %s", filename);                  pfatal("can't open file %s", filename);
   
         if (read(ifd, i_womp, (size_t) i_size) != i_size) {          if (read(ifd, i_womp, (size_t) i_size) != i_size) {
                 close(ifd);     /* probably means i_size > 15 or 16 bits worth */                  close(ifd);     /* probably means i_size > 15 or 16 bits worth */
                 free(i_womp);   /* at this point it doesn't matter if i_womp was */                  free(i_womp);   /* at this point it doesn't matter if i_womp was */
                 return FALSE;   /* undersized. */                  return false;   /* undersized. */
         }          }
   
         close(ifd);          close(ifd);
Line 212 
Line 212 
   
         if (i_ptr == NULL) {    /* shucks, it was a near thing */          if (i_ptr == NULL) {    /* shucks, it was a near thing */
                 free(i_womp);                  free(i_womp);
                 return FALSE;                  return false;
         }          }
         /* now scan the buffer and build pointer array */          /* now scan the buffer and build pointer array */
   
Line 248 
Line 248 
                         say("Good.  This file appears to be the %s version.\n",                          say("Good.  This file appears to be the %s version.\n",
                             revision);                              revision);
         }          }
         return TRUE;            /* plan a will work */          return true;            /* plan a will work */
 }  }
   
 /* Keep (virtually) nothing in memory. */  /* Keep (virtually) nothing in memory. */
Line 260 
Line 260 
         int     i = 0, maxlen = 1;          int     i = 0, maxlen = 1;
         bool    found_revision = (revision == NULL);          bool    found_revision = (revision == NULL);
   
         using_plan_a = FALSE;          using_plan_a = false;
         if ((ifp = fopen(filename, "r")) == NULL)          if ((ifp = fopen(filename, "r")) == NULL)
                 pfatal("can't open file %s", filename);                  pfatal("can't open file %s", filename);
         (void) unlink(TMPINNAME);          (void) unlink(TMPINNAME);
Line 268 
Line 268 
                 pfatal("can't open file %s", TMPINNAME);                  pfatal("can't open file %s", TMPINNAME);
         while (fgets(buf, sizeof buf, ifp) != NULL) {          while (fgets(buf, sizeof buf, ifp) != NULL) {
                 if (revision != NULL && !found_revision && rev_in_string(buf))                  if (revision != NULL && !found_revision && rev_in_string(buf))
                         found_revision = TRUE;                          found_revision = true;
                 if ((i = strlen(buf)) > maxlen)                  if ((i = strlen(buf)) > maxlen)
                         maxlen = i;     /* find longest line */                          maxlen = i;     /* find longest line */
         }          }
Line 331 
Line 331 
         if (line < 1 || line > input_lines) {          if (line < 1 || line > input_lines) {
                 if (warn_on_invalid_line) {                  if (warn_on_invalid_line) {
                         say("No such line %ld in input file, ignoring\n", line);                          say("No such line %ld in input file, ignoring\n", line);
                         warn_on_invalid_line = FALSE;                          warn_on_invalid_line = false;
                 }                  }
                 return NULL;                  return NULL;
         }          }
Line 368 
Line 368 
         int             patlen;          int             patlen;
   
         if (revision == NULL)          if (revision == NULL)
                 return TRUE;                  return true;
         patlen = strlen(revision);          patlen = strlen(revision);
         if (strnEQ(string, revision, patlen) && isspace(string[patlen]))          if (strnEQ(string, revision, patlen) && isspace(string[patlen]))
                 return TRUE;                  return true;
         for (s = string; *s; s++) {          for (s = string; *s; s++) {
                 if (isspace(*s) && strnEQ(s + 1, revision, patlen) &&                  if (isspace(*s) && strnEQ(s + 1, revision, patlen) &&
                     isspace(s[patlen + 1])) {                      isspace(s[patlen + 1])) {
                         return TRUE;                          return true;
                 }                  }
         }          }
         return FALSE;          return false;
 }  }

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22