ucx/buffer.c

changeset 1016
ccde46662db7
parent 995
2f811eae2424
equal deleted inserted replaced
1015:b459361d98ad 1016:ccde46662db7
43 return 0; 43 return 0;
44 } 44 }
45 45
46 int cxBufferInit( 46 int cxBufferInit(
47 CxBuffer *buffer, 47 CxBuffer *buffer,
48 const CxAllocator *allocator,
48 void *space, 49 void *space,
49 size_t capacity, 50 size_t capacity,
50 const CxAllocator *allocator,
51 int flags 51 int flags
52 ) { 52 ) {
53 if (allocator == NULL) { 53 if (allocator == NULL) {
54 allocator = cxDefaultAllocator; 54 allocator = cxDefaultAllocator;
55 } 55 }
56 if (flags & CX_BUFFER_COPY_ON_EXTEND) { 56 if (flags & CX_BUFFER_COPY_ON_EXTEND) {
57 flags |= CX_BUFFER_AUTO_EXTEND; 57 flags |= CX_BUFFER_AUTO_EXTEND;
80 } 80 }
81 memset(buffer, 0, sizeof(CxBuffer)); 81 memset(buffer, 0, sizeof(CxBuffer));
82 } 82 }
83 83
84 CxBuffer *cxBufferCreate( 84 CxBuffer *cxBufferCreate(
85 const CxAllocator *allocator,
85 void *space, 86 void *space,
86 size_t capacity, 87 size_t capacity,
87 const CxAllocator *allocator,
88 int flags 88 int flags
89 ) { 89 ) {
90 if (allocator == NULL) { 90 if (allocator == NULL) {
91 allocator = cxDefaultAllocator; 91 allocator = cxDefaultAllocator;
92 } 92 }
93 CxBuffer *buf = cxMalloc(allocator, sizeof(CxBuffer)); 93 CxBuffer *buf = cxMalloc(allocator, sizeof(CxBuffer));
94 if (buf == NULL) return NULL; // LCOV_EXCL_LINE 94 if (buf == NULL) return NULL; // LCOV_EXCL_LINE
95 if (0 == cxBufferInit(buf, space, capacity, allocator, flags)) { 95 if (0 == cxBufferInit(buf, allocator, space, capacity, flags)) {
96 return buf; 96 return buf;
97 } else { 97 } else {
98 // LCOV_EXCL_START 98 // LCOV_EXCL_START
99 cxFree(allocator, buf); 99 cxFree(allocator, buf);
100 return NULL; 100 return NULL;

mercurial