Project

General

Profile

prelude-inttypes.h

, 01/29/2007 10:32 AM

Download (5.18 KB)

 
1
/*****
2
*
3
* Copyright (C) 2004, 2005 PreludeIDS Technologies. All Rights Reserved.
4
* Author: Yoann Vandoorselaere <yoann.v@prelude-ids.com>
5
*
6
* This file is part of the Prelude library.
7
*
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2, or (at your option)
11
* any later version.
12
*
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
* GNU General Public License for more details.
17
*
18
* You should have received a copy of the GNU General Public License
19
* along with this program; see the file COPYING.  If not, write to
20
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
*
22
*****/
23

    
24
#ifndef _LIBPRELUDE_INTTYPES_H
25
#define _LIBPRELUDE_INTTYPES_H
26

    
27
#ifdef __cplusplus
28
 extern "C" {
29
#endif
30

    
31
/*
32
 * Defined by ax_create_prelude_inttypes_h.m4
33
 */
34
#define __PRELUDE_HAVE_STDINT_H
35
#define __PRELUDE_HAVE_INTTYPES_H
36
/* #define __PRELUDE_HAVE_64BIT_LONG */
37
#define __PRELUDE_STDINT_HAVE_UINT8
38
#define __PRELUDE_STDINT_HAVE_UINT16
39
#define __PRELUDE_STDINT_HAVE_UINT32
40
#define __PRELUDE_STDINT_HAVE_UINT64
41

    
42

    
43
#ifdef __PRELUDE_HAVE_64BIT_LONG
44
 #define __PRELUDE_INT64_SUFFIX(x) x ## L
45
 #define __PRELUDE_UINT64_SUFFIX(x) x ## UL
46
#else
47
 #define __PRELUDE_INT64_SUFFIX(x) x ## LL
48
 #define __PRELUDE_UINT64_SUFFIX(x) x ##ULL
49
#endif
50

    
51
#ifdef HAVE_CONFIG_H
52
# include "config.h"
53
#endif
54

    
55
#ifdef __PRELUDE_HAVE_STDINT_H
56
# include <stdint.h>
57
#endif
58

    
59
#ifdef __PRELUDE_HAVE_INTTYPES_H
60
# include <inttypes.h>
61
#endif
62

    
63

    
64
#ifndef TRUE
65
# define TRUE 1
66
#endif
67

    
68
#ifndef FALSE
69
# define FALSE 0
70
#endif
71

    
72

    
73

    
74
/*
75
 * Minimum of signed integral types.
76
 */
77
#define PRELUDE_INT8_MIN               (-128)
78
#define PRELUDE_INT16_MIN              (-32767 - 1)
79
#define PRELUDE_INT32_MIN              (-2147483647 - 1)
80
#define PRELUDE_INT64_MIN              (-__PRELUDE_INT64_SUFFIX(9223372036854775807) - 1)
81

    
82

    
83

    
84
/*
85
 * Maximum of signed integral types.
86
 */
87
#define PRELUDE_INT8_MAX               (127)
88
#define PRELUDE_INT16_MAX              (32767)
89
#define PRELUDE_INT32_MAX              (2147483647)
90
#define PRELUDE_INT64_MAX              (__PRELUDE_INT64_SUFFIX(9223372036854775807))
91

    
92

    
93
/*
94
 * Maximum of unsigned integral types.
95
 */
96
#define PRELUDE_UINT8_MAX              (255)
97
#define PRELUDE_UINT16_MAX             (65535)
98
#define PRELUDE_UINT32_MAX             (4294967295U)
99
#define PRELUDE_UINT64_MAX             (__PRELUDE_UINT64_SUFFIX(18446744073709551615))
100

    
101

    
102
/*
103
 * Other
104
 */
105
#define PRELUDE_INTMAX_MIN             INT64_MIN
106
#define PRELUDE_INTMAX_MAX             INT64_MAX
107
#define PRELUDE_UINTMAX_MAX            UINT64_MAX
108

    
109

    
110
/* 
111
 * Tandem NonStop R series and compatible platforms released before
112
 * July 2005 support %Ld but not %lld.  
113
 */
114
# if defined _TNS_R_TARGET
115
#  define _LONG_LONG_FORMAT_PREFIX "L"
116
# else
117
#  define _LONG_LONG_FORMAT_PREFIX "ll"
118
# endif
119

    
120
#if PRELUDE_INT64_MAX == LONG_MAX
121
# define __PRELUDE_64BIT_FORMAT_PREFIX "l"
122
#elif defined _MSC_VER || defined __MINGW32__
123
# define __PRELUDE_64BIT_FORMAT_PREFIX "I64"
124
#elif 1 && LONG_MAX >> 30 == 1
125
# define __PRELUDE_64BIT_FORMAT_PREFIX _LONG_LONG_FORMAT_PREFIX
126
#endif
127

    
128

    
129

    
130
/*
131
 * format specifier
132
 */
133
#define PRELUDE_PRId64      __PRELUDE_64BIT_FORMAT_PREFIX "d"
134
#define PRELUDE_PRIi64      __PRELUDE_64BIT_FORMAT_PREFIX "i"
135
#define PRELUDE_PRIo64      __PRELUDE_64BIT_FORMAT_PREFIX "o"
136
#define PRELUDE_PRIx64      __PRELUDE_64BIT_FORMAT_PREFIX "x"
137
#define PRELUDE_PRIX64      __PRELUDE_64BIT_FORMAT_PREFIX "X"
138
#define PRELUDE_PRIu64      __PRELUDE_64BIT_FORMAT_PREFIX "u"
139

    
140
#define PRELUDE_PRId32      "d"
141
#define PRELUDE_PRIi32      "i"
142
#define PRELUDE_PRIo32      "o"
143
#define PRELUDE_PRIx32      "x"
144
#define PRELUDE_PRIX32      "X"
145
#define PRELUDE_PRIu32      "u"
146

    
147
#define PRELUDE_PRId16      "d"
148
#define PRELUDE_PRIi16      "i"
149
#define PRELUDE_PRIo16      "o"
150
#define PRELUDE_PRIx16      "x"
151
#define PRELUDE_PRIX16      "X"
152
#define PRELUDE_PRIu16      "u"
153

    
154
#define PRELUDE_PRId8       "d"
155
#define PRELUDE_PRIi8       "i"
156
#define PRELUDE_PRIo8       "o"
157
#define PRELUDE_PRIx8       "x"
158
#define PRELUDE_PRIX8       "X"
159
#define PRELUDE_PRIu8       "u"
160

    
161
#define PRELUDE_SCNd64      __PRELUDE_64BIT_FORMAT_PREFIX "d"
162
#define PRELUDE_SCNi64      __PRELUDE_64BIT_FORMAT_PREFIX "i"
163
#define PRELUDE_SCNo64      __PRELUDE_64BIT_FORMAT_PREFIX "o"
164
#define PRELUDE_SCNx64      __PRELUDE_64BIT_FORMAT_PREFIX "x"
165
#define PRELUDE_SCNu64      __PRELUDE_64BIT_FORMAT_PREFIX "u"
166

    
167

    
168

    
169

    
170
/*
171
 * Type definition
172
 */
173
typedef enum { 
174
        PRELUDE_BOOL_TRUE = TRUE, 
175
        PRELUDE_BOOL_FALSE = FALSE 
176
} prelude_bool_t;
177

    
178

    
179
#ifndef __PRELUDE_STDINT_HAVE_UINT8
180
 typedef signed char int8_t;
181
 typedef unsigned char uint8_t;
182
#endif
183

    
184

    
185
#ifndef __PRELUDE_STDINT_HAVE_UINT16
186
 typedef short int16_t;
187
 typedef unsigned short uint16_t;
188
#endif
189

    
190
#ifndef __PRELUDE_STDINT_HAVE_UINT32
191
 typedef int int32_t;
192
 typedef unsigned int uint32_t;
193
#endif
194

    
195
#ifndef __PRELUDE_STDINT_HAVE_UINT64
196
# ifdef __PRELUDE_HAVE_64BIT_LONG
197

    
198
  typedef long int64_t;
199
  typedef unsigned long uint64_t;
200

    
201
# else
202

    
203
  typedef long long int64_t;
204
  typedef unsigned long long uint64_t;
205

    
206
# endif
207
#endif
208

    
209
#ifdef __cplusplus
210
 }
211
#endif
212

    
213
#endif /* _LIBPRELUDE_INTTYPES_H */