version 1.1, 2013/10/14 10:32:47
|
version 1.1.1.2, 2014/06/15 20:20:06
|
Line 25 buffer* buffer_init(void) {
|
Line 25 buffer* buffer_init(void) {
|
buffer *b; |
buffer *b; |
|
|
b = malloc(sizeof(*b)); |
b = malloc(sizeof(*b)); |
assert(b); | force_assert(b); |
|
|
b->ptr = NULL; |
b->ptr = NULL; |
b->size = 0; |
b->size = 0; |
Line 90 int buffer_prepare_copy(buffer *b, size_t size) {
|
Line 90 int buffer_prepare_copy(buffer *b, size_t size) {
|
b->size += BUFFER_PIECE_SIZE - (b->size % BUFFER_PIECE_SIZE); |
b->size += BUFFER_PIECE_SIZE - (b->size % BUFFER_PIECE_SIZE); |
|
|
b->ptr = malloc(b->size); |
b->ptr = malloc(b->size); |
assert(b->ptr); | force_assert(b->ptr); |
} |
} |
b->used = 0; |
b->used = 0; |
return 0; |
return 0; |
Line 114 int buffer_prepare_append(buffer *b, size_t size) {
|
Line 114 int buffer_prepare_append(buffer *b, size_t size) {
|
|
|
b->ptr = malloc(b->size); |
b->ptr = malloc(b->size); |
b->used = 0; |
b->used = 0; |
assert(b->ptr); | force_assert(b->ptr); |
} else if (b->used + size > b->size) { |
} else if (b->used + size > b->size) { |
b->size += size; |
b->size += size; |
|
|
Line 122 int buffer_prepare_append(buffer *b, size_t size) {
|
Line 122 int buffer_prepare_append(buffer *b, size_t size) {
|
b->size += BUFFER_PIECE_SIZE - (b->size % BUFFER_PIECE_SIZE); |
b->size += BUFFER_PIECE_SIZE - (b->size % BUFFER_PIECE_SIZE); |
|
|
b->ptr = realloc(b->ptr, b->size); |
b->ptr = realloc(b->ptr, b->size); |
assert(b->ptr); | force_assert(b->ptr); |
} |
} |
return 0; |
return 0; |
} |
} |
Line 419 buffer_array* buffer_array_init(void) {
|
Line 419 buffer_array* buffer_array_init(void) {
|
|
|
b = malloc(sizeof(*b)); |
b = malloc(sizeof(*b)); |
|
|
assert(b); | force_assert(b); |
b->ptr = NULL; |
b->ptr = NULL; |
b->size = 0; |
b->size = 0; |
b->used = 0; |
b->used = 0; |
Line 463 buffer *buffer_array_append_get_buffer(buffer_array *b
|
Line 463 buffer *buffer_array_append_get_buffer(buffer_array *b
|
if (b->size == 0) { |
if (b->size == 0) { |
b->size = 16; |
b->size = 16; |
b->ptr = malloc(sizeof(*b->ptr) * b->size); |
b->ptr = malloc(sizeof(*b->ptr) * b->size); |
assert(b->ptr); | force_assert(b->ptr); |
for (i = 0; i < b->size; i++) { |
for (i = 0; i < b->size; i++) { |
b->ptr[i] = NULL; |
b->ptr[i] = NULL; |
} |
} |
} else if (b->size == b->used) { |
} else if (b->size == b->used) { |
b->size += 16; |
b->size += 16; |
b->ptr = realloc(b->ptr, sizeof(*b->ptr) * b->size); |
b->ptr = realloc(b->ptr, sizeof(*b->ptr) * b->size); |
assert(b->ptr); | force_assert(b->ptr); |
for (i = b->used; i < b->size; i++) { |
for (i = b->used; i < b->size; i++) { |
b->ptr[i] = NULL; |
b->ptr[i] = NULL; |
} |
} |
Line 584 int buffer_is_equal_right_len(buffer *b1, buffer *b2,
|
Line 584 int buffer_is_equal_right_len(buffer *b1, buffer *b2,
|
if (b1->used == 0 || b2->used == 0) return 0; |
if (b1->used == 0 || b2->used == 0) return 0; |
|
|
/* buffers too small -> not equal */ |
/* buffers too small -> not equal */ |
if (b1->used - 1 < len || b1->used - 1 < len) return 0; | if (b1->used - 1 < len || b2->used - 1 < len) return 0; |
|
|
if (0 == strncmp(b1->ptr + b1->used - 1 - len, |
if (0 == strncmp(b1->ptr + b1->used - 1 - len, |
b2->ptr + b2->used - 1 - len, len)) { |
b2->ptr + b2->used - 1 - len, len)) { |
Line 783 int buffer_append_string_encoded(buffer *b, const char
|
Line 783 int buffer_append_string_encoded(buffer *b, const char
|
break; |
break; |
} |
} |
|
|
assert(map != NULL); | force_assert(map != NULL); |
|
|
/* count to-be-encoded-characters */ |
/* count to-be-encoded-characters */ |
for (ds = (unsigned char *)s, d_len = 0, ndx = 0; ndx < s_len; ds++, ndx++) { |
for (ds = (unsigned char *)s, d_len = 0, ndx = 0; ndx < s_len; ds++, ndx++) { |
Line 1057 int buffer_to_upper(buffer *b) {
|
Line 1057 int buffer_to_upper(buffer *b) {
|
} |
} |
|
|
return 0; |
return 0; |
|
} |
|
|
|
void log_failed_assert(const char *filename, unsigned int line, const char *msg) { |
|
/* can't use buffer here; could lead to recursive assertions */ |
|
fprintf(stderr, "%s.%d: %s\n", filename, line, msg); |
|
fflush(stderr); |
|
abort(); |
} |
} |