45 if (!space) { |
45 if (!space) { |
46 buffer->bytes = cxMalloc(allocator, capacity); |
46 buffer->bytes = cxMalloc(allocator, capacity); |
47 if (buffer->bytes == NULL) { |
47 if (buffer->bytes == NULL) { |
48 return 1; |
48 return 1; |
49 } |
49 } |
50 memset(buffer->bytes, 0, capacity); |
|
51 buffer->flags |= CX_BUFFER_FREE_CONTENTS; |
50 buffer->flags |= CX_BUFFER_FREE_CONTENTS; |
52 } else { |
51 } else { |
53 buffer->bytes = space; |
52 buffer->bytes = space; |
54 } |
53 } |
55 buffer->capacity = capacity; |
54 buffer->capacity = capacity; |
120 return 0; |
119 return 0; |
121 } |
120 } |
122 |
121 |
123 unsigned char *newspace = realloc(buffer->bytes, newcap); |
122 unsigned char *newspace = realloc(buffer->bytes, newcap); |
124 if (newspace) { |
123 if (newspace) { |
125 memset(newspace + buffer->size, 0, newcap - buffer->size); |
|
126 buffer->bytes = newspace; |
124 buffer->bytes = newspace; |
127 buffer->capacity = newcap; |
125 buffer->capacity = newcap; |
|
126 return 0; |
128 } else { |
127 } else { |
129 return -1; |
128 return -1; |
130 } |
129 } |
131 |
|
132 return 0; |
|
133 } |
130 } |
134 |
131 |
135 size_t cxBufferWrite( |
132 size_t cxBufferWrite( |
136 void const *ptr, |
133 void const *ptr, |
137 size_t size, |
134 size_t size, |