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/lo.h"
22 
lo_blob_new(int32_t size,const void * data)23 lo_blob lo_blob_new(int32_t size, const void *data)
24 {
25     lo_blob b;
26 
27     if (size < 1) {
28         return NULL;
29     }
30 
31     b = (lo_blob) malloc(sizeof(size) + size);
32 
33     b->size = size;
34 
35     if (data) {
36         memcpy((char*) b + sizeof(uint32_t), data, size);
37     }
38 
39     return b;
40 }
41 
lo_blob_free(lo_blob b)42 void lo_blob_free(lo_blob b)
43 {
44     free(b);
45 }
46 
lo_blob_datasize(lo_blob b)47 uint32_t lo_blob_datasize(lo_blob b)
48 {
49     return b->size;
50 }
51 
lo_blob_dataptr(lo_blob b)52 void *lo_blob_dataptr(lo_blob b)
53 {
54     return (char*) b + sizeof(uint32_t);
55 }
56 
lo_blobsize(lo_blob b)57 uint32_t lo_blobsize(lo_blob b)
58 {
59     const uint32_t len = sizeof(uint32_t) + b->size;
60 
61     return 4 * ((len + 3) / 4);
62 }
63 
64 /* vi:set ts=8 sts=4 sw=4: */
65