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

Diff for /src/usr.bin/file/file.c between version 1.41 and 1.42

version 1.41, 2015/05/29 11:03:37 version 1.42, 2015/05/29 11:59:01
Line 371 
Line 371 
 }  }
   
 static void *  static void *
 fill_buffer(struct input_file *inf)  fill_buffer(int fd, size_t size, size_t *used)
 {  {
         static void     *buffer;          static void     *buffer;
         ssize_t          got;          ssize_t          got;
Line 382 
Line 382 
                 buffer = xmalloc(FILE_READ_SIZE);                  buffer = xmalloc(FILE_READ_SIZE);
   
         next = buffer;          next = buffer;
         left = inf->size;          left = size;
         while (left != 0) {          while (left != 0) {
                 got = read(inf->fd, next, left);                  got = read(fd, next, left);
                 if (got == -1) {                  if (got == -1) {
                         if (errno == EINTR)                          if (errno == EINTR)
                                 continue;                                  continue;
Line 395 
Line 395 
                 next = (char *)next + got;                  next = (char *)next + got;
                 left -= got;                  left -= got;
         }          }
         inf->size -= left;          *used = size - left;
         return buffer;          return buffer;
 }  }
   
 static int  static int
 load_file(struct input_file *inf)  load_file(struct input_file *inf)
 {  {
           size_t  used;
   
         inf->size = inf->msg->sb.st_size;          inf->size = inf->msg->sb.st_size;
         if (inf->size > FILE_READ_SIZE)          if (inf->size > FILE_READ_SIZE)
                 inf->size = FILE_READ_SIZE;                  inf->size = FILE_READ_SIZE;
Line 414 
Line 416 
   
         inf->base = mmap(NULL, inf->size, PROT_READ, MAP_PRIVATE, inf->fd, 0);          inf->base = mmap(NULL, inf->size, PROT_READ, MAP_PRIVATE, inf->fd, 0);
         if (inf->base == MAP_FAILED) {          if (inf->base == MAP_FAILED) {
                 inf->base = fill_buffer(inf);                  inf->base = fill_buffer(inf->fd, inf->size, &used);
                 if (inf->base == NULL) {                  if (inf->base == NULL) {
                         xasprintf(&inf->result, "cannot read '%s' (%s)",                          xasprintf(&inf->result, "cannot read '%s' (%s)",
                             inf->path, strerror(errno));                              inf->path, strerror(errno));
                         return (1);                          return (1);
                 }                  }
                   inf->size = used;
         } else          } else
                 inf->mapped = 1;                  inf->mapped = 1;
         return (0);          return (0);

Legend:
Removed from v.1.41  
changed lines
  Added in v.1.42