From 29cd51d1f9f9a96848ea7b8a4bb72aeadfa2077a Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 9 Jul 2008 18:32:37 +0000 Subject: [PATCH] added a buffer_chomp function to drop the last character from the buffer git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1363 9efc2488-bf62-4759-914b-345cdb29e865 --- include/opensrf/utils.h | 1 + src/libopensrf/utils.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/include/opensrf/utils.h b/include/opensrf/utils.h index dcdba02..f6cb272 100644 --- a/include/opensrf/utils.h +++ b/include/opensrf/utils.h @@ -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); +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* diff --git a/src/libopensrf/utils.c b/src/libopensrf/utils.c index 01fd382..4a22b02 100644 --- a/src/libopensrf/utils.c +++ b/src/libopensrf/utils.c @@ -280,6 +280,15 @@ char* buffer_data( const growing_buffer *gb) { 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)\ -- 2.11.0