mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
575 B
42 lines
575 B
16 years ago
|
#include <oi_buf.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
void oi_buf_destroy
|
||
|
( oi_buf *buf
|
||
|
)
|
||
|
{
|
||
|
free(buf->base);
|
||
|
free(buf);
|
||
|
}
|
||
|
|
||
|
oi_buf * oi_buf_new2
|
||
|
( size_t len
|
||
|
)
|
||
|
{
|
||
|
oi_buf *buf = malloc(sizeof(oi_buf));
|
||
|
if(!buf)
|
||
|
return NULL;
|
||
|
buf->base = malloc(len);
|
||
|
if(!buf->base) {
|
||
|
free(buf);
|
||
|
return NULL;
|
||
|
}
|
||
|
buf->len = len;
|
||
|
buf->release = oi_buf_destroy;
|
||
|
return buf;
|
||
|
}
|
||
|
|
||
|
oi_buf * oi_buf_new
|
||
|
( const char *base
|
||
|
, size_t len
|
||
|
)
|
||
|
{
|
||
|
oi_buf *buf = oi_buf_new2(len);
|
||
|
if(!buf)
|
||
|
return NULL;
|
||
|
memcpy(buf->base, base, len);
|
||
|
return buf;
|
||
|
}
|
||
|
|