enhanced a little

This commit is contained in:
TLINDEN
2014-02-10 11:33:20 +01:00
parent 57bcd9325b
commit b5e8e0de03
2 changed files with 8 additions and 2 deletions

View File

@@ -51,7 +51,7 @@ struct _pcp_buffer {
typedef struct _pcp_buffer Buffer;
/* create a new buffer */
/* create a new buffer, initially alloc'd to blocksize and zero-filled */
Buffer *buffer_new(size_t blocksize, char *name);
/* zero the buffer and free it, if allocated */

View File

@@ -21,9 +21,16 @@
#include "buffer.h"
Buffer *buffer_new(size_t blocksize, char *name) {
Buffer *b = ucmalloc(sizeof(Buffer));
b->buf = ucmalloc(blocksize);
buffer_init(b, blocksize, name);
return b;
}
void buffer_init(Buffer *b, size_t blocksize, char *name) {
b->name = ucmalloc(strlen(name)+1);
b->size = blocksize;
b->allocated = 1;
@@ -31,7 +38,6 @@ Buffer *buffer_new(size_t blocksize, char *name) {
b->end = 0;
b->blocksize = blocksize;
memcpy(b->name, name, strlen(name)+1);
return b;
}
void buffer_free(Buffer *b) {