CSL  5.2
blob.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004 Steve Harris
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 
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 = 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 
43 {
44  free(b);
45 }
46 
48 {
49  return b->size;
50 }
51 
53 {
54  return (char*)b + sizeof(uint32_t);
55 }
56 
57 uint32_t lo_blobsize(lo_blob b)
58 {
59  const uint32_t len = sizeof(uint32_t) + b->size;
60 
61  return 4 * (len / 4 + 1);
62 }
63 
64 /* vi:set ts=8 sts=4 sw=4: */