4 * @brief Pointer/lenght abstraction and its functions.
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
32 typedef struct chunk_t chunk_t
;
35 * General purpose pointer/length abstraction.
38 /** Pointer to start of data */
40 /** Length of data in bytes */
45 * A { NULL, 0 }-chunk handy for initialization.
47 extern chunk_t chunk_empty
;
50 * Initialize a chunk to point to a static(!) buffer
52 #define chunk_from_buf(str) { str, sizeof(str) }
55 * Clone chunk contents in a newly allocated chunk
57 chunk_t
chunk_clone(chunk_t chunk
);
60 * Allocate a chunk from concatenation of other chunks.
61 * mode is a string 'm' and 'c, 'm' means move chunk,
62 * 'c' means copy chunk.
64 chunk_t
chunk_cat(const char* mode
, ...);
67 * Free contents of a chunk
69 void chunk_free(chunk_t
*chunk
);
74 chunk_t
chunk_alloc(size_t bytes
);
77 * Compare two chunks for equality,
78 * NULL chunks are never equal.
80 bool chunk_equals(chunk_t a
, chunk_t b
);
83 * Compare two chunks for equality,
84 * NULL chunks are always equal.
86 bool chunk_equals_or_null(chunk_t a
, chunk_t b
);