fixed 64 bit issue
[strongswan.git] / src / libstrongswan / chunk.h
1 /**
2 * @file chunk.h
3 *
4 * @brief Pointer/lenght abstraction and its functions.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
12 *
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>.
17 *
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
21 * for more details.
22 */
23
24 #ifndef CHUNK_H_
25 #define CHUNK_H_
26
27 #include <string.h>
28 #include <stdarg.h>
29
30 #include <library.h>
31
32 typedef struct chunk_t chunk_t;
33
34 /**
35 * General purpose pointer/length abstraction.
36 */
37 struct chunk_t {
38 /** Pointer to start of data */
39 u_char *ptr;
40 /** Length of data in bytes */
41 size_t len;
42 };
43
44 /**
45 * A { NULL, 0 }-chunk handy for initialization.
46 */
47 extern chunk_t chunk_empty;
48
49 /**
50 * Initialize a chunk to point to a static(!) buffer
51 */
52 #define chunk_from_buf(str) { str, sizeof(str) }
53
54 /**
55 * Clone chunk contents in a newly allocated chunk
56 */
57 chunk_t chunk_clone(chunk_t chunk);
58
59 /**
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.
63 */
64 chunk_t chunk_cat(const char* mode, ...);
65
66 /**
67 * Free contents of a chunk
68 */
69 void chunk_free(chunk_t *chunk);
70
71 /**
72 * Allocate a chunk
73 */
74 chunk_t chunk_alloc(size_t bytes);
75
76 /**
77 * Compare two chunks for equality,
78 * NULL chunks are never equal.
79 */
80 bool chunk_equals(chunk_t a, chunk_t b);
81
82 /**
83 * Compare two chunks for equality,
84 * NULL chunks are always equal.
85 */
86 bool chunk_equals_or_null(chunk_t a, chunk_t b);
87
88 #endif /* CHUNK_H_ */