utils.c
// Allocate data for a new string buffer, rounding initial_size up to a power of two.
Allocate data for a new string buffer, rounding initial_size up to a power of two.
Allocate data for a new string buffer rounding initial_size up to a power of two .
StringBuffer *new_string_buffer(int initial_size) {
    StringBuffer *sb = malloc(sizeof(StringBuffer));
    sb->position = 0;
    int allocated = 1;
    while (allocated < initial_size * 2) allocated <<= 1;
    sb->allocated = allocated;
    sb->data = malloc(allocated);
    return sb;
}
StringBuffer * new_string_buffer ( int initial_size ) { StringBuffer * sb = malloc ( sizeof ( StringBuffer ) ) ; sb -> position = 0 ; int allocated = 1 ; while ( allocated < initial_size * 2 ) allocated <<= 1 ; sb -> allocated = allocated ; sb -> data = malloc ( allocated ) ; return sb ; }
Allocate data for a new string buffer, rounding initial_size up to a power of two.
Allocate data for a new string buffer rounding initial_size up to a power of two .