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

Diff for /src/usr.bin/cvs/buf.c between version 1.79 and 1.80

version 1.79, 2010/09/08 15:13:39 version 1.80, 2010/09/08 20:49:11
Line 40 
Line 40 
 #define BUF_INCR        128  #define BUF_INCR        128
   
 struct buf {  struct buf {
           /* buffer handle, buffer size, and data length */
         u_char  *cb_buf;          u_char  *cb_buf;
         size_t   cb_size;          size_t   cb_size;
         size_t   cb_len;          size_t   cb_len;
Line 49 
Line 50 
   
 static void     buf_grow(BUF *, size_t);  static void     buf_grow(BUF *, size_t);
   
   /*
    * Create a new buffer structure and return a pointer to it.  This structure
    * uses dynamically-allocated memory and must be freed with buf_free(), once
    * the buffer is no longer needed.
    */
 BUF *  BUF *
 buf_alloc(size_t len)  buf_alloc(size_t len)
 {  {
Line 67 
Line 73 
         return (b);          return (b);
 }  }
   
   /*
    * Open the file specified by <path> and load all of its contents into a
    * buffer.
    * Returns the loaded buffer.
    */
 BUF *  BUF *
 buf_load(const char *path)  buf_load(const char *path)
 {  {
Line 112 
Line 123 
         xfree(b);          xfree(b);
 }  }
   
   /*
    * Free the buffer <b>'s structural information but do not free the contents
    * of the buffer.  Instead, they are returned and should be freed later using
    * xfree().
    */
 void *  void *
 buf_release(BUF *b)  buf_release(BUF *b)
 {  {
Line 122 
Line 138 
         return (tmp);          return (tmp);
 }  }
   
   /*
    * Append a single character <c> to the end of the buffer <b>.
    */
 void  void
 buf_putc(BUF *b, int c)  buf_putc(BUF *b, int c)
 {  {
Line 134 
Line 153 
         b->cb_len++;          b->cb_len++;
 }  }
   
   /*
    * Append a C-string <str> to the end of the buffer <b>.
    */
 void  void
 buf_puts(BUF *b, const char *str)  buf_puts(BUF *b, const char *str)
 {  {
         buf_append(b, str, strlen(str));          buf_append(b, str, strlen(str));
 }  }
   
   /*
    * Append <len> bytes of data pointed to by <data> to the buffer <b>.  If the
    * buffer is too small to accept all data, it will get resized to an
    * appropriate size to accept all data.
    */
 void  void
 buf_append(BUF *b, const void *data, size_t len)  buf_append(BUF *b, const void *data, size_t len)
 {  {
Line 156 
Line 183 
         b->cb_len += len;          b->cb_len += len;
 }  }
   
   /*
    * Returns the size of the buffer that is being used.
    */
 size_t  size_t
 buf_len(BUF *b)  buf_len(BUF *b)
 {  {
         return (b->cb_len);          return (b->cb_len);
 }  }
   
   /*
    * Write the contents of the buffer <b> to the specified <fd>
    */
 int  int
 buf_write_fd(BUF *b, int fd)  buf_write_fd(BUF *b, int fd)
 {  {
Line 170 
Line 203 
         return (0);          return (0);
 }  }
   
   /*
    * Write the contents of the buffer <b> to the file whose path is given in
    * <path>.  If the file does not exist, it is created with mode <mode>.
    */
 int  int
 buf_write(BUF *b, const char *path, mode_t mode)  buf_write(BUF *b, const char *path, mode_t mode)
 {  {
Line 195 
Line 232 
         return (0);          return (0);
 }  }
   
   /*
    * Write the contents of the buffer <b> to a temporary file whose path is
    * specified using <template> (see mkstemp.3). If <tv> is specified file
    * access and modification time is set to <tv>.
    * NB. This function will modify <template>, as per mkstemp
    */
 int  int
 buf_write_stmp(BUF *b, char *template, struct timeval *tv)  buf_write_stmp(BUF *b, char *template, struct timeval *tv)
 {  {
Line 237 
Line 280 
 }  }
   
 /*  /*
  * buf_grow()  
  *  
  * Grow the buffer <b> by <len> bytes.  The contents are unchanged by this   * Grow the buffer <b> by <len> bytes.  The contents are unchanged by this
  * operation regardless of the result.   * operation regardless of the result.
  */   */

Legend:
Removed from v.1.79  
changed lines
  Added in v.1.80