e4089c4ff0bda7de9fe5d2429e80a2ceb4488366
[strongswan.git] / src / libstrongswan / printf_hook.c
1 /**
2 * @file printf_hook.c
3 *
4 * @brief Printf hook definitions and arginfo functions.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006 Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
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>.
16 *
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
20 * for more details.
21 */
22
23 #include "printf_hook.h"
24
25 /**
26 * arginfo handler in printf() pointer
27 */
28 int arginfo_ptr(const struct printf_info *info, size_t n, int *argtypes)
29 {
30 if (n > 0)
31 {
32 argtypes[0] = PA_POINTER;
33 }
34 return 1;
35 }
36
37 /**
38 * arginfo handler for one ptr, one int
39 */
40 int arginfo_ptr_int(const struct printf_info *info, size_t n, int *argtypes)
41 {
42 if (n > 1)
43 {
44 argtypes[0] = PA_POINTER;
45 argtypes[1] = PA_INT;
46 }
47 return 2;
48 }
49
50 /**
51 * arginfo handler for two int arguments
52 */
53 int arginfo_int_int(const struct printf_info *info, size_t n, int *argtypes)
54 {
55 if (n > 1)
56 {
57 argtypes[0] = PA_INT;
58 argtypes[1] = PA_INT;
59 }
60 return 2;
61 }
62
63 /**
64 * special arginfo handler respecting alt flag
65 */
66 int arginfo_int_alt_int_int(const struct printf_info *info, size_t n, int *argtypes)
67 {
68 if (info->alt)
69 {
70 if (n > 1)
71 {
72 argtypes[0] = PA_INT;
73 argtypes[1] = PA_INT;
74 }
75 return 2;
76 }
77
78 if (n > 0)
79 {
80 argtypes[0] = PA_INT;
81 }
82 return 1;
83 }
84
85 /**
86 * special arginfo handler respecting alt flag
87 */
88 int arginfo_ptr_alt_ptr_int(const struct printf_info *info, size_t n, int *argtypes)
89 {
90 if (info->alt)
91 {
92 if (n > 1)
93 {
94 argtypes[0] = PA_POINTER;
95 argtypes[1] = PA_INT;
96 }
97 return 2;
98 }
99
100 if (n > 0)
101 {
102 argtypes[0] = PA_POINTER;
103 }
104 return 1;
105 }