Eliminated four dead functions that are never called
[OpenSRF.git] / include / opensrf / utils.h
index a42bc06..ab24e8f 100644 (file)
@@ -41,7 +41,7 @@ GNU General Public License for more details.
                memset( ptr, 0, size );\
        } while(0)
 
-#ifndef NDEBUG
+#ifdef NDEBUG
 // The original ... replace with noop once no more errors occur in NDEBUG mode
 #define osrf_clearbuf( s, n ) memset( s, 0, n )
 #else
@@ -56,31 +56,55 @@ GNU General Public License for more details.
 
 #define OSRF_BUFFER_ADD(gb, data) \
        do {\
-               int __tl; \
-               if(gb && data) {\
-                       __tl = strlen(data) + gb->n_used;\
-                       if( __tl < gb->size ) {\
-                               strcat(gb->buf, data);\
-                               gb->n_used = __tl; \
-                       } else { buffer_add(gb, data); }\
+               int _tl; \
+               growing_buffer* _gb = gb; \
+               const char* _data = data; \
+               if(_gb && _data) {\
+                       _tl = strlen(_data) + _gb->n_used;\
+                       if( _tl < _gb->size ) {\
+                               strcpy( _gb->buf + _gb->n_used, _data ); \
+                               _gb->n_used = _tl; \
+                       } else { buffer_add(_gb, _data); }\
                }\
        } while(0)
 
+#define OSRF_BUFFER_ADD_N(gb, data, n) \
+       do {\
+               growing_buffer* gb__ = gb; \
+               const char* data__ = data; \
+               size_t n__ = n; \
+               if(gb__ && data__) {\
+                       int tl__ = n__ + gb__->n_used;\
+                       if( tl__ < gb__->size ) {\
+                               memcpy( gb__->buf + gb__->n_used, data__, n__ ); \
+                               gb__->buf[tl__] = '\0'; \
+                               gb__->n_used = tl__; \
+} else { buffer_add_n(gb__, data__, n__); }\
+}\
+} while(0)
+
 #define OSRF_BUFFER_ADD_CHAR(gb, c)\
        do {\
-               if(gb) {\
-                       if(gb->n_used < gb->size - 1)\
-                               gb->buf[gb->n_used++] = c;\
+               growing_buffer* _gb = gb;\
+               char _c = c;\
+               if(_gb) {\
+                       if(_gb->n_used < _gb->size - 1) {\
+                               _gb->buf[_gb->n_used++] = _c;\
+                               _gb->buf[_gb->n_used]   = '\0';\
+                       }\
                        else\
-                               buffer_add_char(gb, c);\
+                               buffer_add_char(_gb, _c);\
                }\
        }while(0)
 
 #define OSRF_BUFFER_RESET(gb) \
-    memset(gb->buf, 0, gb->size);\
-    gb->n_used = 0;
+       do {\
+               growing_buffer* _gb = gb;\
+       memset(_gb->buf, 0, _gb->size);\
+       _gb->n_used = 0;\
+       }while(0)
 
-       
+#define OSRF_BUFFER_C_STR( x ) ((const char *) (x)->buf)
 
 
 /* turns a va_list into a string */
@@ -183,18 +207,22 @@ struct growing_buffer_struct {
 };
 typedef struct growing_buffer_struct growing_buffer;
 
+#define buffer_length(x) (x)->n_used
+
 growing_buffer* buffer_init( int initial_num_bytes);
 
 // XXX This isn't defined in utils.c!! removing for now...
 //int buffer_addchar(growing_buffer* gb, char c);
 
 int buffer_add(growing_buffer* gb, const char* c);
+int buffer_add_n(growing_buffer* gb, const char* data, size_t n);
 int buffer_fadd(growing_buffer* gb, const char* format, ... );
 int buffer_reset( growing_buffer* gb);
 char* buffer_data( const growing_buffer* gb);
 char* buffer_release( growing_buffer* gb );
 int buffer_free( growing_buffer* gb );
 int buffer_add_char(growing_buffer* gb, char c);
+char buffer_chomp(growing_buffer* gb); // removes the last character from the buffer
 
 /* returns the size needed to fill in the vsnprintf buffer.  
        * ! this calls va_end on the va_list argument*
@@ -206,7 +234,7 @@ long va_list_size(const char* format, va_list);
 char* va_list_to_string(const char* format, ...);
 
 
-/* string escape utility method.  escapes unicode embeded characters.
+/* string escape utility method.  escapes unicode embedded characters.
        escapes the usual \n, \t, etc. 
        for example, if you provide a string like so:
 
@@ -232,12 +260,6 @@ double get_timestamp_millis( void );
 /* returns true if the whole string is a number */
 int stringisnum(const char* s);
 
-/* reads a file and returns the string version of the file
-       user is responsible for freeing the returned char*
-       */
-char* file_to_string(const char* filename);
-
-
 
 /** 
   Calculates the md5 of the text provided.