66 |
66 |
67 void cxBufferDestroy(CxBuffer *buffer) { |
67 void cxBufferDestroy(CxBuffer *buffer) { |
68 if ((buffer->flags & CX_BUFFER_FREE_CONTENTS) == CX_BUFFER_FREE_CONTENTS) { |
68 if ((buffer->flags & CX_BUFFER_FREE_CONTENTS) == CX_BUFFER_FREE_CONTENTS) { |
69 cxFree(buffer->allocator, buffer->bytes); |
69 cxFree(buffer->allocator, buffer->bytes); |
70 } |
70 } |
|
71 } |
|
72 |
|
73 CxBuffer *cxBufferCreate( |
|
74 void *space, |
|
75 size_t capacity, |
|
76 CxAllocator const *allocator, |
|
77 int flags |
|
78 ) { |
|
79 CxBuffer *buf = cxMalloc(allocator, sizeof(CxBuffer)); |
|
80 if (buf == NULL) return NULL; |
|
81 if (0 == cxBufferInit(buf, space, capacity, allocator, flags)) { |
|
82 return buf; |
|
83 } else { |
|
84 cxFree(allocator, buf); |
|
85 return NULL; |
|
86 } |
|
87 } |
|
88 |
|
89 void cxBufferFree(CxBuffer *buffer) { |
|
90 if ((buffer->flags & CX_BUFFER_FREE_CONTENTS) == CX_BUFFER_FREE_CONTENTS) { |
|
91 cxFree(buffer->allocator, buffer->bytes); |
|
92 } |
|
93 cxFree(buffer->allocator, buffer); |
71 } |
94 } |
72 |
95 |
73 int cxBufferSeek( |
96 int cxBufferSeek( |
74 CxBuffer *buffer, |
97 CxBuffer *buffer, |
75 off_t offset, |
98 off_t offset, |