raw
mpi-genesis             1 /* types.h - some common typedefs
mpi-genesis 2 * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
mpi-genesis 3 *
mpi-genesis 4 * This file is part of GNUPG.
mpi-genesis 5 *
mpi-genesis 6 * GNUPG is free software; you can redistribute it and/or modify
mpi-genesis 7 * it under the terms of the GNU General Public License as published by
mpi-genesis 8 * the Free Software Foundation; either version 3 of the License, or
mpi-genesis 9 * (at your option) any later version.
mpi-genesis 10 *
mpi-genesis 11 * GNUPG is distributed in the hope that it will be useful,
mpi-genesis 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
mpi-genesis 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
mpi-genesis 14 * GNU General Public License for more details.
mpi-genesis 15 *
mpi-genesis 16 * You should have received a copy of the GNU General Public License
mpi-genesis 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
mpi-genesis 18 */
mpi-genesis 19
mpi-genesis 20 #ifndef G10_TYPES_H
mpi-genesis 21 #define G10_TYPES_H
mpi-genesis 22
mpi-genesis 23 #ifdef HAVE_INTTYPES_H
mpi-genesis 24 /* For uint64_t */
mpi-genesis 25 #include <inttypes.h>
mpi-genesis 26 #endif
mpi-genesis 27
mpi-genesis 28 /* The AC_CHECK_SIZEOF() in configure fails for some machines.
mpi-genesis 29 * we provide some fallback values here */
mpi-genesis 30 #if !SIZEOF_UNSIGNED_SHORT
mpi-genesis 31 #undef SIZEOF_UNSIGNED_SHORT
mpi-genesis 32 #define SIZEOF_UNSIGNED_SHORT 2
mpi-genesis 33 #endif
mpi-genesis 34 #if !SIZEOF_UNSIGNED_INT
mpi-genesis 35 #undef SIZEOF_UNSIGNED_INT
mpi-genesis 36 #define SIZEOF_UNSIGNED_INT 4
mpi-genesis 37 #endif
mpi-genesis 38 #if !SIZEOF_UNSIGNED_LONG
mpi-genesis 39 #undef SIZEOF_UNSIGNED_LONG
mpi-genesis 40 #define SIZEOF_UNSIGNED_LONG 4
mpi-genesis 41 #endif
mpi-genesis 42
mpi-genesis 43
mpi-genesis 44 #include <sys/types.h>
mpi-genesis 45
mpi-genesis 46
mpi-genesis 47 #ifndef HAVE_BYTE_TYPEDEF
mpi-genesis 48 #undef byte /* maybe there is a macro with this name */
mpi-genesis 49 #ifndef __riscos__
mpi-genesis 50 typedef unsigned char byte;
mpi-genesis 51 #else
mpi-genesis 52 /* Norcroft treats char = unsigned char as legal assignment
mpi-genesis 53 but char* = unsigned char* as illegal assignment
mpi-genesis 54 and the same applies to the signed variants as well */
mpi-genesis 55 typedef char byte;
mpi-genesis 56 #endif
mpi-genesis 57 #define HAVE_BYTE_TYPEDEF
mpi-genesis 58 #endif
mpi-genesis 59
mpi-genesis 60 #ifndef HAVE_USHORT_TYPEDEF
mpi-genesis 61 #undef ushort /* maybe there is a macro with this name */
mpi-genesis 62 typedef unsigned short ushort;
mpi-genesis 63 #define HAVE_USHORT_TYPEDEF
mpi-genesis 64 #endif
mpi-genesis 65
mpi-genesis 66 #ifndef HAVE_ULONG_TYPEDEF
mpi-genesis 67 #undef ulong /* maybe there is a macro with this name */
mpi-genesis 68 typedef unsigned long ulong;
mpi-genesis 69 #define HAVE_ULONG_TYPEDEF
mpi-genesis 70 #endif
mpi-genesis 71
mpi-genesis 72 #ifndef HAVE_U16_TYPEDEF
mpi-genesis 73 #undef u16 /* maybe there is a macro with this name */
mpi-genesis 74 #if SIZEOF_UNSIGNED_INT == 2
mpi-genesis 75 typedef unsigned int u16;
mpi-genesis 76 #elif SIZEOF_UNSIGNED_SHORT == 2
mpi-genesis 77 typedef unsigned short u16;
mpi-genesis 78 #else
mpi-genesis 79 #error no typedef for u16
mpi-genesis 80 #endif
mpi-genesis 81 #define HAVE_U16_TYPEDEF
mpi-genesis 82 #endif
mpi-genesis 83
mpi-genesis 84 #ifndef HAVE_U32_TYPEDEF
mpi-genesis 85 #undef u32 /* maybe there is a macro with this name */
mpi-genesis 86 #if SIZEOF_UNSIGNED_INT == 4
mpi-genesis 87 typedef unsigned int u32;
mpi-genesis 88 #elif SIZEOF_UNSIGNED_LONG == 4
mpi-genesis 89 typedef unsigned long u32;
mpi-genesis 90 #else
mpi-genesis 91 #error no typedef for u32
mpi-genesis 92 #endif
mpi-genesis 93 #define HAVE_U32_TYPEDEF
mpi-genesis 94 #endif
mpi-genesis 95
mpi-genesis 96 /****************
mpi-genesis 97 * Warning: Some systems segfault when this u64 typedef and
mpi-genesis 98 * the dummy code in cipher/md.c is not available. Examples are
mpi-genesis 99 * Solaris and IRIX.
mpi-genesis 100 */
mpi-genesis 101 #ifndef HAVE_U64_TYPEDEF
mpi-genesis 102 #undef u64 /* maybe there is a macro with this name */
mpi-genesis 103 #if SIZEOF_UINT64_T == 8
mpi-genesis 104 typedef uint64_t u64;
mpi-genesis 105 #define U64_C(c) (UINT64_C(c))
mpi-genesis 106 #define HAVE_U64_TYPEDEF
mpi-genesis 107 #elif SIZEOF_UNSIGNED_INT == 8
mpi-genesis 108 typedef unsigned int u64;
mpi-genesis 109 #define U64_C(c) (c ## U)
mpi-genesis 110 #define HAVE_U64_TYPEDEF
mpi-genesis 111 #elif SIZEOF_UNSIGNED_LONG == 8
mpi-genesis 112 typedef unsigned long u64;
mpi-genesis 113 #define U64_C(c) (c ## UL)
mpi-genesis 114 #define HAVE_U64_TYPEDEF
mpi-genesis 115 #elif SIZEOF_UNSIGNED_LONG_LONG == 8
mpi-genesis 116 typedef unsigned long long u64;
mpi-genesis 117 #define U64_C(c) (c ## ULL)
mpi-genesis 118 #define HAVE_U64_TYPEDEF
mpi-genesis 119 #endif
mpi-genesis 120 #endif
mpi-genesis 121
mpi-genesis 122 typedef union {
mpi-genesis 123 int a;
mpi-genesis 124 short b;
mpi-genesis 125 char c[1];
mpi-genesis 126 long d;
mpi-genesis 127 #ifdef HAVE_U64_TYPEDEF
mpi-genesis 128 u64 e;
mpi-genesis 129 #endif
mpi-genesis 130 float f;
mpi-genesis 131 double g;
mpi-genesis 132 } PROPERLY_ALIGNED_TYPE;
mpi-genesis 133
mpi-genesis 134 struct string_list {
mpi-genesis 135 struct string_list *next;
mpi-genesis 136 unsigned int flags;
mpi-genesis 137 char d[1];
mpi-genesis 138 };
mpi-genesis 139 typedef struct string_list *STRLIST;
mpi-genesis 140 typedef struct string_list *strlist_t;
mpi-genesis 141
mpi-genesis 142 #endif /*G10_TYPES_H*/