4 * @brief Generic types.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
29 * String mappings for type status_t.
31 mapping_t status_m
[] = {
34 {OUT_OF_RES
, "OUT_OF_RES"},
35 {ALREADY_DONE
, "ALREADY_DONE"},
36 {NOT_SUPPORTED
, "NOT_SUPPORTED"},
37 {INVALID_ARG
, "INVALID_ARG"},
38 {NOT_FOUND
, "NOT_FOUND"},
39 {PARSE_ERROR
, "PARSE_ERROR"},
40 {VERIFY_ERROR
, "VERIFY_ERROR"},
41 {INVALID_STATE
, "INVALID_STATE"},
42 {DELETE_ME
, "DELETE_ME"},
50 chunk_t CHUNK_INITIALIZER
= {NULL
,0};
53 * Described in header.
55 chunk_t
chunk_clone(chunk_t chunk
)
57 chunk_t clone
= CHUNK_INITIALIZER
;
59 if (chunk
.ptr
&& chunk
.len
> 0)
61 clone
.ptr
= malloc(chunk
.len
);
62 clone
.len
= chunk
.len
;
63 memcpy(clone
.ptr
, chunk
.ptr
, chunk
.len
);
70 * Described in header.
72 void chunk_free(chunk_t
*chunk
)
80 * Described in header.
82 chunk_t
chunk_alloc(size_t bytes
)
85 new_chunk
.ptr
= malloc(bytes
);
86 new_chunk
.len
= bytes
;
91 * Described in header.
93 bool chunk_equals(chunk_t a
, chunk_t b
)
95 if (a
.ptr
== NULL
|| b
.ptr
== NULL
||
97 memcmp(a
.ptr
, b
.ptr
, a
.len
) != 0)
105 * Described in header.
107 void *clalloc(void * pointer
, size_t size
)
112 memcpy(data
, pointer
,size
);