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

Diff for /src/usr.bin/rcs/buf.c between version 1.7 and 1.8

version 1.7, 2006/08/02 03:28:50 version 1.8, 2006/08/16 07:39:15
Line 81 
Line 81 
  *   *
  * Open the file specified by <path> and load all of its contents into a   * Open the file specified by <path> and load all of its contents into a
  * buffer.   * buffer.
  * Returns the loaded buffer on success.   * Returns the loaded buffer on success or NULL on failure.
    * Sets errno on error.
  */   */
 BUF *  BUF *
 rcs_buf_load(const char *path, u_int flags)  rcs_buf_load(const char *path, u_int flags)
Line 93 
Line 94 
         struct stat st;          struct stat st;
         BUF *buf;          BUF *buf;
   
         if ((fd = open(path, O_RDONLY, 0600)) == -1) {          buf = NULL;
                 warn("%s", path);  
                 return (NULL);  
         }  
   
           if ((fd = open(path, O_RDONLY, 0600)) == -1)
                   goto out;
   
         if (fstat(fd, &st) == -1)          if (fstat(fd, &st) == -1)
                 err(1, "%s", path);                  goto out;
   
         buf = rcs_buf_alloc((size_t)st.st_size, flags);          if (st.st_size > SIZE_MAX) {
                   errno = EFBIG;
                   goto out;
           }
           buf = rcs_buf_alloc(st.st_size, flags);
         for (bp = buf->cb_cur; ; bp += (size_t)ret) {          for (bp = buf->cb_cur; ; bp += (size_t)ret) {
                 len = SIZE_LEFT(buf);                  len = SIZE_LEFT(buf);
                 ret = read(fd, bp, len);                  ret = read(fd, bp, len);
                 if (ret == -1) {                  if (ret == -1) {
                           int saved_errno;
   
                           saved_errno = errno;
                         rcs_buf_free(buf);                          rcs_buf_free(buf);
                         err(1, "rcs_buf_load");                          buf = NULL;
                           errno = saved_errno;
                           goto out;
                 } else if (ret == 0)                  } else if (ret == 0)
                         break;                          break;
   
                 buf->cb_len += (size_t)ret;                  buf->cb_len += (size_t)ret;
         }          }
   
         (void)close(fd);  out:
           if (fd != -1) {
                   int saved_errno;
   
                   /* We may want to preserve errno here. */
                   saved_errno = errno;
                   (void)close(fd);
                   errno = saved_errno;
           }
   
         return (buf);          return (buf);
 }  }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8