}\
} 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) {\
//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);
return total_len;
}
+/** Append a specified number of characters to a growing_buffer.
+ If the characters so appended include an embedded nul, the results
+ are likely to be unhappy.
+*/
+int buffer_add_n(growing_buffer* gb, const char* data, size_t n) {
+ if(!(gb && data)) return 0;
+
+ if(n == 0) return 0;
+
+ int total_len = n + gb->n_used;
+
+ if( total_len >= gb->size ) {
+ if( buffer_expand( gb, total_len ) )
+ return -1;
+ }
+
+ memcpy( gb->buf + gb->n_used, data, n );
+ gb->buf[total_len] = '\0';
+ gb->n_used = total_len;
+ return total_len;
+}
+
int buffer_reset( growing_buffer *gb){
if( gb == NULL ) { return -1; }