op_growable_buffer.c

Go to the documentation of this file.
00001 
00011 #include "op_growable_buffer.h"
00012 #include "op_libiberty.h"
00013 
00014 #include <string.h>
00015 #include <stdlib.h>
00016 
00017 void init_buffer(struct growable_buffer * b)
00018 {
00019     b->max_size = 0;
00020     b->size = 0;
00021     b->p = NULL;
00022 }
00023 
00024 
00025 void free_buffer(struct growable_buffer * b)
00026 {
00027     free(b->p);
00028 }
00029 
00030 
00031 static void grow_buffer(struct growable_buffer * b)
00032 {
00033     size_t new_size = (b->max_size + b->size) * 2;
00034     b->p = xrealloc(b->p, new_size);
00035     b->max_size = new_size;
00036 }
00037 
00038 
00039 void add_data(struct growable_buffer * b, void const * data, size_t len)
00040 {
00041     size_t old_size = b->size;
00042     b->size += len;
00043     if (b->size > b->max_size)
00044         grow_buffer(b);
00045     memcpy(b->p + old_size, data, len);
00046 }

Generated on 8 Nov 2012 for Oprofile by  doxygen 1.6.1