summaryrefslogtreecommitdiff
path: root/m4/types.m4
blob: bf13428cb645237958759c5a80d77e3e1d043a6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
dnl AC_COMPILE_CHECK_SIZEOF (TYPE SUPPOSED-SIZE)
dnl abort if the given type does not have the supposed size
AC_DEFUN([AC_COMPILE_CHECK_SIZEOF], [
    AC_MSG_CHECKING(that size of $1 is $2)
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[switch (0) case 0: case (sizeof ($1) == $2):;]])],
                      [AC_MSG_RESULT([yes])], [AC_MSG_ERROR([can not build a default inttypes.h])])
])


dnl AC_CHECK_GENERATE_INTTYPES_H (INCLUDE-DIRECTORY)
dnl generate a default inttypes.h if the header file does not exist already
AC_DEFUN([AC_CHECK_GENERATE_INTTYPES],
    [AC_CHECK_HEADER([inttypes.h],,
        [if test ! -d $1; then mkdir $1; fi
        AC_CHECK_HEADER([stdint.h],
            [cat >$1/inttypes.h << EOF
#ifndef _INTTYPES_H
#define _INTTYPES_H
/* helper inttypes.h for people who do not have it on their system */

#include <stdint.h>
EOF
            ],
            [AC_COMPILE_CHECK_SIZEOF([char],[1])
            AC_COMPILE_CHECK_SIZEOF([short],[2])
            AC_COMPILE_CHECK_SIZEOF([int],[4])
            AC_COMPILE_CHECK_SIZEOF([long long],[8])
        cat >$1/inttypes.h << EOF
#ifndef _INTTYPES_H
#define _INTTYPES_H
/* default inttypes.h for people who do not have it on their system */
#if (!defined __int8_t_defined) && (!defined __BIT_TYPES_DEFINED__)
#define __int8_t_defined
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
#ifdef ARCH_X86
typedef signed long long int64_t;
#endif
#endif
#if (!defined __uint8_t_defined) && (!defined _LINUX_TYPES_H)
#define __uint8_t_defined
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#ifdef ARCH_X86
typedef unsigned long long uint64_t;
#endif
#endif
EOF
            ])
        cat >>$1/inttypes.h << EOF

#ifdef WIN32
#  define PRI64_PREFIX "I64"
#else
#  define PRI64_PREFIX "l"
#endif

#ifndef PRId8
#  define PRId8 "d"
#endif
#ifndef PRId16
#  define PRId16 "d"
#endif
#ifndef PRId32
#  define PRId32 "d"
#endif
#ifndef PRId64
#  define PRId64 PRI64_PREFIX "d"
#endif

#ifndef PRIu8
#  define PRIu8 "u"
#endif
#ifndef PRIu16
#  define PRIu16 "u"
#endif
#ifndef PRIu32
#  define PRIu32 "u"
#endif
#ifndef PRIu64
#  define PRIu64 PRI64_PREFIX "u"
#endif

#ifndef PRIx8
#  define PRIx8 "x"
#endif
#ifndef PRIx16
#  define PRIx16 "x"
#endif
#ifndef PRIx32
#  define PRIx32 "x"
#endif
#ifndef PRIx64
#  define PRIx64 PRI64_PREFIX "x"
#endif

#ifndef PRIX8
#  define PRIX8 "X"
#endif
#ifndef PRIX16
#  define PRIX16 "X"
#endif
#ifndef PRIX32
#  define PRIX32 "X"
#endif
#ifndef PRIX64
#  define PRIX64 PRI64_PREFIX "X"
#endif

#ifndef PRIdFAST8
#  define PRIdFAST8 "d"
#endif
#ifndef PRIdFAST16
#  define PRIdFAST16 "d"
#endif
#ifndef PRIdFAST32
#  define PRIdFAST32 "d"
#endif
#ifndef PRIdFAST64
#  define PRIdFAST64 "d"
#endif

#ifndef PRIuFAST8
#  define PRIuFAST8 "u"
#endif
#ifndef PRIuFAST16
#  define PRIuFAST16 "u"
#endif
#ifndef PRIuFAST32
#  define PRIuFAST32 "u"
#endif
#ifndef PRIuFAST64
#  define PRIuFAST64 PRI64_PREFIX "u"
#endif

#ifndef PRIxFAST8
#  define PRIxFAST8 "x"
#endif
#ifndef PRIxFAST16
#  define PRIxFAST16 "x"
#endif
#ifndef PRIxFAST32
#  define PRIxFAST32 "x"
#endif
#ifndef PRIxFAST64
#  define PRIxFAST64 PRI64_PREFIX "x"
#endif

#ifndef SCNd8
#  define SCNd8 "hhd"
#endif
#ifndef SCNd16
#  define SCNd16 "hd"
#endif
#ifndef SCNd32
#  define SCNd32 "d"
#endif
#ifndef SCNd64
#  define SCNd64 PRI64_PREFIX "d"
#endif

#ifndef SCNu8
#  define SCNu8 "hhu"
#endif
#ifndef SCNu16
#  define SCNu16 "hu"
#endif
#ifndef SCNu32
#  define SCNu32 "u"
#endif
#ifndef SCNu64
#  define SCNu64 PRI64_PREFIX "u"
#endif

#ifndef PRIdMAX
#  define PRIdMAX PRId64
#endif
#ifndef PRIuMAX
#  define PRIuMAX PRIu64
#endif
#ifndef PRIxMAX
#  define PRIxMAX PRIx64
#endif
#ifndef SCNdMAX
#  define SCNdMAX SCNd64
#endif

#endif
EOF
        ])])


dnl Check for the type of the third argument of getsockname
AC_DEFUN([AC_CHECK_SOCKLEN_T], [
    AC_MSG_CHECKING([for socklen_t])
    AC_LANG_PUSH([C])
    AC_CACHE_VAL([ac_cv_socklen_t],
                 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
                                                       #include <sys/socket.h>]],
                                                     [[socklen_t a=0; getsockname(0,(struct sockaddr*)0, &a)]])],
                                    [ac_cv_socklen_t=socklen_t], [ac_cv_socklen_t=''])
                  if test x"$ac_cv_socklen_t" = x""; then
                      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
                                                           #include <sys/socket.h>]],
                                                         [[int a=0; getsockname(0,(struct sockaddr*)0, &a);]])],
                                        [ac_cv_socklen_t=int], [ac_cv_socklen_t=size_t])
                  fi])
    AC_LANG_POP([C])
    AC_MSG_RESULT([$ac_cv_socklen_t])
    if test x"$ac_cv_socklen_t" != x"socklen_t"; then
        AC_DEFINE_UNQUOTED([socklen_t], [$ac_cv_socklen_t], [Define the real type of socklen_t])
    fi
])