chiark / gitweb /
Replace use of variable-length-arrays.
[gnupg2.git] / common / types.h
1 /* types.h - define some extra types
2  *      Copyright (C) 1999, 2000, 2001, 2006 Free Software Foundation, Inc.
3  *
4  * This file is part of GnuPG.
5  *
6  * GnuPG is free software; you can redistribute it and/or modify it
7  * under the terms of either
8  *
9  *   - the GNU Lesser General Public License as published by the Free
10  *     Software Foundation; either version 3 of the License, or (at
11  *     your option) any later version.
12  *
13  * or
14  *
15  *   - the GNU General Public License as published by the Free
16  *     Software Foundation; either version 2 of the License, or (at
17  *     your option) any later version.
18  *
19  * or both in parallel, as here.
20  *
21  * GnuPG is distributed in the hope that it will be useful, but
22  * WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24  * General Public License for more details.
25  *
26  * You should have received a copies of the GNU General Public License
27  * and the GNU Lesser General Public License along with this program;
28  * if not, see <https://www.gnu.org/licenses/>.
29  */
30
31 #ifndef GNUPG_COMMON_TYPES_H
32 #define GNUPG_COMMON_TYPES_H
33
34 #ifdef HAVE_INTTYPES_H
35 # include <inttypes.h>
36 #endif
37
38 /* The AC_CHECK_SIZEOF() in configure fails for some machines.
39  * we provide some fallback values here */
40 #if !SIZEOF_UNSIGNED_SHORT
41 #  undef SIZEOF_UNSIGNED_SHORT
42 #  define SIZEOF_UNSIGNED_SHORT 2
43 #endif
44 #if !SIZEOF_UNSIGNED_INT
45 #  undef SIZEOF_UNSIGNED_INT
46 #  define SIZEOF_UNSIGNED_INT 4
47 #endif
48 #if !SIZEOF_UNSIGNED_LONG
49 #  undef SIZEOF_UNSIGNED_LONG
50 #  define SIZEOF_UNSIGNED_LONG 4
51 #endif
52
53
54 #include <sys/types.h>
55
56
57 /* We use byte as an abbreviation for unsigned char.  On some
58    platforms this needs special treatment:
59
60    - RISC OS:
61      Norcroft C treats char  = unsigned char  as legal assignment
62                    but char* = unsigned char* as illegal assignment
63      and the same applies to the signed variants as well.  Thus we use
64      char which is anyway unsigned.
65
66    - Windows:
67      Windows typedefs byte in the RPC headers but we need to avoid a
68      warning about a double definition.
69  */
70 #ifndef HAVE_BYTE_TYPEDEF
71 #  undef byte       /* There might be a macro with this name.  */
72 #  ifdef __riscos__
73      typedef char byte;
74 #  elif !(defined(_WIN32) && defined(cbNDRContext))
75      typedef unsigned char byte;
76 #  endif
77 #  define HAVE_BYTE_TYPEDEF
78 #endif /*!HAVE_BYTE_TYPEDEF*/
79
80 #ifndef HAVE_USHORT_TYPEDEF
81 #  undef ushort     /* There might be a macro with this name.  */
82    typedef unsigned short ushort;
83 #  define HAVE_USHORT_TYPEDEF
84 #endif
85
86 #ifndef HAVE_ULONG_TYPEDEF
87 #  undef ulong      /* There might be a macro with this name.  */
88    typedef unsigned long ulong;
89 #  define HAVE_ULONG_TYPEDEF
90 #endif
91
92 #ifndef HAVE_U16_TYPEDEF
93 #  undef u16        /* There might be a macro with this name.  */
94 #  if SIZEOF_UNSIGNED_INT == 2
95      typedef unsigned int   u16;
96 #  elif SIZEOF_UNSIGNED_SHORT == 2
97      typedef unsigned short u16;
98 #  else
99 #    error no typedef for u16
100 #  endif
101 #  define HAVE_U16_TYPEDEF
102 #endif
103
104 #ifndef HAVE_U32_TYPEDEF
105 #  undef u32        /* There might be a macro with this name.  */
106 #  if SIZEOF_UNSIGNED_INT == 4
107      typedef unsigned int u32;
108 #  elif SIZEOF_UNSIGNED_LONG == 4
109      typedef unsigned long u32;
110 #  else
111 #    error no typedef for u32
112 #  endif
113 #  define HAVE_U32_TYPEDEF
114 #endif
115
116 #endif /*GNUPG_COMMON_TYPES_H*/