Debian Codegraph @

src/core/lo/blob.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2014 Steve Harris et al. (see AUTHORS)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation; either version 2.1 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * $Id$
15 */
16
17 #include <stdlib.h>
18 #include <string.h>
19
20 #include "lo_types_internal.h"
21 #include "lo.h"
22
23 lo_blob lo_blob_new(int32_t size, const void *data)
24 {
25 lo_blob b;
26
27 if (size < 0) {
28 return NULL;
29 }
30
31 b = (lo_blob) malloc(sizeof(size) + size);
32
33 b->size = size;
34
35 if (size && data) {
36 memcpy((char*) b + sizeof(uint32_t), data, size);
37 }
38
39 return b;
40 }
41
42 void lo_blob_free(lo_blob b)
43 {
44 free(b);
45 }
46
47 uint32_t lo_blob_datasize(lo_blob b)
48 {
49 return b->size;
50 }
51
52 void *lo_blob_dataptr(lo_blob b)
53 {
54 return b->size
55 ? (char*) b + sizeof(uint32_t)
56 : NULL;
57 }
58
59 uint32_t lo_blobsize(lo_blob b)
60 {
61 const uint32_t len = sizeof(uint32_t) + b->size;
62
63 return 4 * ((len + 3) / 4);
64 }
65
66 /* vi:set ts=8 sts=4 sw=4: */