2007-05-19 Marcus Brinkmann <marcus@g10code.de>
[gnupg.git] / include / types.h
blob6abd500e357a747fed5b6022d262c1e3929ff6d1
1 /* types.h - some common typedefs
2 * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG 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 Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GnuPG 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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 * USA.
22 #ifndef G10_TYPES_H
23 #define G10_TYPES_H
25 #ifdef HAVE_INTTYPES_H
26 /* For uint64_t */
27 #include <inttypes.h>
28 #endif
30 /* The AC_CHECK_SIZEOF() in configure fails for some machines.
31 * we provide some fallback values here */
32 #if !SIZEOF_UNSIGNED_SHORT
33 #undef SIZEOF_UNSIGNED_SHORT
34 #define SIZEOF_UNSIGNED_SHORT 2
35 #endif
36 #if !SIZEOF_UNSIGNED_INT
37 #undef SIZEOF_UNSIGNED_INT
38 #define SIZEOF_UNSIGNED_INT 4
39 #endif
40 #if !SIZEOF_UNSIGNED_LONG
41 #undef SIZEOF_UNSIGNED_LONG
42 #define SIZEOF_UNSIGNED_LONG 4
43 #endif
46 #include <sys/types.h>
49 #ifndef HAVE_BYTE_TYPEDEF
50 #undef byte /* maybe there is a macro with this name */
51 #ifndef __riscos__
52 typedef unsigned char byte;
53 #else
54 /* Norcroft treats char = unsigned char as legal assignment
55 but char* = unsigned char* as illegal assignment
56 and the same applies to the signed variants as well */
57 typedef char byte;
58 #endif
59 #define HAVE_BYTE_TYPEDEF
60 #endif
62 #ifndef HAVE_USHORT_TYPEDEF
63 #undef ushort /* maybe there is a macro with this name */
64 typedef unsigned short ushort;
65 #define HAVE_USHORT_TYPEDEF
66 #endif
68 #ifndef HAVE_ULONG_TYPEDEF
69 #undef ulong /* maybe there is a macro with this name */
70 typedef unsigned long ulong;
71 #define HAVE_ULONG_TYPEDEF
72 #endif
74 #ifndef HAVE_U16_TYPEDEF
75 #undef u16 /* maybe there is a macro with this name */
76 #if SIZEOF_UNSIGNED_INT == 2
77 typedef unsigned int u16;
78 #elif SIZEOF_UNSIGNED_SHORT == 2
79 typedef unsigned short u16;
80 #else
81 #error no typedef for u16
82 #endif
83 #define HAVE_U16_TYPEDEF
84 #endif
86 #ifndef HAVE_U32_TYPEDEF
87 #undef u32 /* maybe there is a macro with this name */
88 #if SIZEOF_UNSIGNED_INT == 4
89 typedef unsigned int u32;
90 #elif SIZEOF_UNSIGNED_LONG == 4
91 typedef unsigned long u32;
92 #else
93 #error no typedef for u32
94 #endif
95 #define HAVE_U32_TYPEDEF
96 #endif
98 /****************
99 * Warning: Some systems segfault when this u64 typedef and
100 * the dummy code in cipher/md.c is not available. Examples are
101 * Solaris and IRIX.
103 #ifndef HAVE_U64_TYPEDEF
104 #undef u64 /* maybe there is a macro with this name */
105 #if SIZEOF_UINT64_T == 8
106 typedef uint64_t u64;
107 #define U64_C(c) (UINT64_C(c))
108 #define HAVE_U64_TYPEDEF
109 #elif SIZEOF_UNSIGNED_INT == 8
110 typedef unsigned int u64;
111 #define U64_C(c) (c ## U)
112 #define HAVE_U64_TYPEDEF
113 #elif SIZEOF_UNSIGNED_LONG == 8
114 typedef unsigned long u64;
115 #define U64_C(c) (c ## UL)
116 #define HAVE_U64_TYPEDEF
117 #elif SIZEOF_UNSIGNED_LONG_LONG == 8
118 typedef unsigned long long u64;
119 #define U64_C(c) (c ## ULL)
120 #define HAVE_U64_TYPEDEF
121 #endif
122 #endif
124 typedef union {
125 int a;
126 short b;
127 char c[1];
128 long d;
129 #ifdef HAVE_U64_TYPEDEF
130 u64 e;
131 #endif
132 float f;
133 double g;
134 } PROPERLY_ALIGNED_TYPE;
136 #endif /*G10_TYPES_H*/