Debian Codegraph @

src/gen-help.h

raw
1 /* gen-help.c - Helper functions used by build time tools
2 * Copyright (C) 2010 g10 Code GmbH
3 *
4 * This file is part of KSBA.
5 *
6 * KSBA is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Fountion; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * KSBA is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 /* This header has definitions used by programs which are only run on
21 the build platform as part of the build process. They need to be
22 plain ISO C and don't make use of any information gathered from the
23 configure run. */
24
25 #ifndef GEN_HELP_H
26 #define GEN_HELP_H
27
28 #ifndef BUILD_GENTOOLS
29 #error file may only be used for build time tools
30 #endif
31
32
33 void *xmalloc (size_t n);
34 void *xcalloc (size_t n, size_t m);
35 void *xrealloc (void *mem, size_t n);
36 char *xstrdup (const char *str);
37 void xfree (void *a);
38 #define xtrymalloc(a) malloc ((a))
39
40 char *gen_help_stpcpy (char *a, const char *b);
41 #define stpcpy(a, b) gen_help_stpcpy ((a), (b))
42
43
44
45
46 #define DIM(v) (sizeof(v)/sizeof((v)[0]))
47 #define DIMof(type,member) DIM(((type *)0)->member)
48 #ifndef STR
49 # define STR(v) #v
50 #endif
51 #ifndef STR2
52 # define STR2(v) STR(v)
53 #endif
54
55 #define return_if_fail(expr) do { \
56 if (!(expr)) { \
57 fprintf (stderr, "%s:%d: assertion `%s' failed\n", \
58 __FILE__, __LINE__, #expr ); \
59 return; \
60 } } while (0)
61 #define return_null_if_fail(expr) do { \
62 if (!(expr)) { \
63 fprintf (stderr, "%s:%d: assertion `%s' failed\n", \
64 __FILE__, __LINE__, #expr ); \
65 return NULL; \
66 } } while (0)
67 #define return_val_if_fail(expr,val) do { \
68 if (!(expr)) { \
69 fprintf (stderr, "%s:%d: assertion `%s' failed\n", \
70 __FILE__, __LINE__, #expr ); \
71 return (val); \
72 } } while (0)
73 #define never_reached() do { \
74 fprintf (stderr, "%s:%d: oops; should never get here\n", \
75 __FILE__, __LINE__ ); \
76 } while (0)
77
78
79 /* Replacement for gpg_error.h stuff. */
80 #define GPG_ERR_GENERAL 1
81 #define GPG_ERR_SYNTAX 29
82 #define GPG_ERR_INV_VALUE 55
83 #define GPG_ERR_BUG 59
84 #define GPG_ERR_ELEMENT_NOT_FOUND 136
85 #define GPG_ERR_IDENTIFIER_NOT_FOUND 137
86
87 #define gpg_error(a) (a)
88 #define gpg_error_from_syserror() (GPG_ERR_GENERAL);
89 const char *gpg_strerror (int err);
90
91 /* Duplicated type definitions from ksba.h. */
92 typedef struct ksba_asn_tree_s *ksba_asn_tree_t;
93 int ksba_asn_parse_file (const char *filename, ksba_asn_tree_t *result,
94 int debug);
95 void ksba_asn_tree_dump (ksba_asn_tree_t tree, const char *name, FILE *fp);
96
97 #endif /*GEN_HELP_H*/