added
[strongswan.git] / src / libstrongswan / definitions.c
1 /**
2 * @file definitions.c
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 *
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 #include <stdlib.h>
25
26 #include "definitions.h"
27
28 /*
29 * Described in header.
30 */
31 char *mapping_find(mapping_t * maps, int value)
32 {
33 int i = 0;
34 while (maps[i].value != MAPPING_END)
35 {
36 if (maps[i].value == value)
37 {
38 return maps[i].string;
39 }
40 i++;
41 }
42 return "INVALID MAPPING";
43 }
44
45 /*
46 * Described in header
47 */
48 const char *enum_name(enum_names *ed, unsigned long val)
49 {
50 enum_names *p;
51
52 for (p = ed; p != NULL; p = p->en_next_range)
53 {
54 if (p->en_first <= val && val <= p->en_last)
55 return p->en_names[val - p->en_first];
56 }
57 return NULL;
58 }
59