added a buffer_chomp function to drop the last character from the buffer
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 9 Jul 2008 18:32:37 +0000 (18:32 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 9 Jul 2008 18:32:37 +0000 (18:32 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1363 9efc2488-bf62-4759-914b-345cdb29e865

include/opensrf/utils.h
src/libopensrf/utils.c

index dcdba02..f6cb272 100644 (file)
@@ -195,6 +195,7 @@ 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_release( growing_buffer* gb );
 int buffer_free( growing_buffer* gb );
 int buffer_add_char(growing_buffer* gb, char c);
+int 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*
 
 /* returns the size needed to fill in the vsnprintf buffer.  
        * ! this calls va_end on the va_list argument*
index 01fd382..4a22b02 100644 (file)
@@ -280,6 +280,15 @@ char* buffer_data( const growing_buffer *gb) {
        return strdup( gb->buf );
 }
 
        return strdup( gb->buf );
 }
 
+int buffer_chomp(growing_buffer* gb) {
+       if( gb == NULL ) { return -1; }
+    if(gb->n_used > 0) {
+           gb->n_used--;
+           gb->buf[gb->n_used] = '\0';
+    }
+    return gb->n_used;
+}
+
 
 /*
 #define OSRF_BUFFER_ADD_CHAR(gb, c)\
 
 /*
 #define OSRF_BUFFER_ADD_CHAR(gb, c)\