The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / liboi / oi_buf.c @ 90fc8d36

History | View | Annotate | Download (575 Bytes)

1 40c0f755 Ryan
#include <oi_buf.h>
2
#include <stdlib.h>
3
#include <string.h>
4
5
void oi_buf_destroy 
6
  ( oi_buf *buf
7
  )
8
{
9
  free(buf->base);
10
  free(buf);
11
}
12
13
oi_buf * oi_buf_new2
14
  ( size_t len
15
  )
16
{
17
  oi_buf *buf = malloc(sizeof(oi_buf));
18
  if(!buf) 
19
    return NULL;
20
  buf->base = malloc(len);
21
  if(!buf->base) {
22
    free(buf);
23
    return NULL; 
24
  }
25
  buf->len = len;
26
  buf->release = oi_buf_destroy;
27
  return buf;
28
}
29
30
oi_buf * oi_buf_new
31
  ( const char *base
32
  , size_t len
33
  )
34
{
35
  oi_buf *buf = oi_buf_new2(len);
36
  if(!buf) 
37
    return NULL;
38
  memcpy(buf->base, base, len);
39
  return buf;
40
}