buffer.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2005- The University of Notre Dame
00003 This software is distributed under the GNU General Public License.
00004 See the file COPYING for details.
00005 */
00006 
00007 #ifndef BUFFER_H
00008 #define BUFFER_H
00009 
00010 #include <stdlib.h>
00011 #include <stdarg.h>
00012 
00019 #if !(defined(__GNUC__) || defined(__clang__)) && !defined(__attribute__)
00020 #define __attribute__(x) /* do nothing */
00021 #endif
00022 
00023 typedef struct buffer {
00024         char *buf; /* buf points to the start of the buffer, which may be a buffer on the stack or heap */
00025         char *end; /* the current end of the buffer */
00026         size_t len; /* current size of buffer */
00027         size_t max; /* maximum size of buffer */
00028         int abort_on_failure; /* call debug.c fatal(...) on error instead of returning  */
00029 
00030         char initial[1<<12]; /* a reasonably sized buffer to use initially so we avoid (numerous) heap allocations */
00031 
00032         /* a user provided buffer which replaces initial if larger */
00033         struct {
00034                 char *buf;
00035                 size_t len;
00036         } ubuf;
00037 } buffer_t;
00038 
00048 void buffer_init(buffer_t * b);
00049 
00060 void buffer_ubuf(buffer_t * b, char *buf, size_t len);
00061 
00067 void buffer_max(buffer_t * b, size_t max);
00068 
00074 void buffer_abortonfailure(buffer_t * b, int abortonfailure);
00075 
00079 void buffer_free(buffer_t * b);
00080 
00090 int buffer_putvfstring(buffer_t * b, const char *format, va_list ap);
00091 #define buffer_vprintf buffer_putvfstring
00092 
00100 int buffer_putfstring(buffer_t * b, const char *format, ...)
00101 __attribute__ (( format(printf,2,3) )) ;
00102 #define buffer_printf buffer_putfstring
00103 
00110 int buffer_putlstring(buffer_t * b, const char *str, size_t len);
00111 
00117 #define buffer_putstring(b,s)  (buffer_putlstring(b,s,strlen(s)))
00118 
00124 #define buffer_putliteral(b,l)  (buffer_putlstring(b,l "",sizeof(l)-1))
00125 
00133 const char *buffer_tostring(buffer_t * b, size_t * size);
00134 
00140 void buffer_rewind(buffer_t * b, size_t n);
00141 
00147 size_t buffer_pos(buffer_t * b);
00148 
00149 #endif /* BUFFER_H */

Generated on 26 Aug 2014 for cctools by  doxygen 1.6.1