[go: up one dir, main page]

Menu

[ab0eb4]: / src / blob.c  Maximize  Restore  History

Download this file

65 lines (50 with data), 1.3 kB

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