chunk_to_hex() function declaration deleted
[strongswan.git] / src / libstrongswan / definitions.h
1 /**
2 * @file definitions.h
3 *
4 * @brief General purpose definitions and macros.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
12 * Copyright (C) 1998, 1999 D. Hugh Redelmeier. (Endian stuff)
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
23 */
24
25 #ifndef DEFINITIONS_H_
26 #define DEFINITIONS_H_
27
28 #include <stddef.h>
29
30 #define BITS_PER_BYTE 8
31
32 /**
33 * Default length for various auxiliary text buffers
34 */
35 #define BUF_LEN 512
36
37 /**
38 * Macro compares two strings for equality
39 */
40 #define streq(x,y) (strcmp(x, y) == 0)
41
42 /**
43 * Macro compares two binary blobs for equality
44 */
45 #define memeq(x,y,len) (memcmp(x, y, len) == 0)
46
47 /**
48 * Macro gives back larger of two values.
49 */
50 #define max(x,y) ((x) > (y) ? (x):(y))
51
52 /**
53 * Macro gives back smaller of two values.
54 */
55 #define min(x,y) ((x) < (y) ? (x):(y))
56
57 /**
58 * Call destructor of a object if object != NULL
59 */
60 #define DESTROY_IF(obj) if (obj) obj->destroy(obj)
61
62 /**
63 * Debug macro to follow control flow
64 */
65 #define POS printf("%s, line %d\n", __FILE__, __LINE__)
66
67 /**
68 * Macro to allocate a sized type.
69 */
70 #define malloc_thing(thing) ((thing*)malloc(sizeof(thing)))
71
72 /**
73 * Assign a function as a class method
74 */
75 #define ASSIGN(method, function) (method = (typeof(method))function)
76
77 /**
78 * printf() specifier to resolf enum names, see enum_names
79 */
80 #define ENUM_PRINTF_SPEC 'N'
81
82 typedef struct enum_name_t enum_name_t;
83
84 /**
85 * Struct to store names for enums. Use the convenience macros
86 * to define these.
87 * For a single range, use:
88 * ENUM(name, first, last, string1, string2, ...)
89 *
90 * For multiple ranges, use:
91 * ENUM_BEGIN(name, first, last, string1, string2, ...)
92 * ENUM_NEXT(name, first, last, last_from_previous, string3, ...)
93 * ENUM_NEXT(name, first, last, last_from_previous, string4, ...)
94 * ENUM_END(name, last_from_previous)
95 */
96 struct enum_name_t {
97 long first;
98 long last;
99 enum_name_t *next;
100 char *names[];
101 };
102
103 #define ENUM_BEGIN(name, first, last, ...) static enum_name_t name##last = {first, last, NULL, { __VA_ARGS__ }}
104 #define ENUM_NEXT(name, first, last, prev, ...) static enum_name_t name##last = {first, last, &name##prev, { __VA_ARGS__ }}
105 #define ENUM_END(name, prev) enum_name_t *name = &name##prev;
106 #define ENUM(name, first, last, ...) ENUM_BEGIN(name, first, last, __VA_ARGS__); ENUM_END(name, last)
107
108 #endif /*DEFINITIONS_H_*/