common revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
1633838b8255282d10af15c5c84cee5a51466712Bob Halleyiff AST_COMMON
8f34db7d4e391cde13f398a2a72ad009980d12feBob Halleyhdr pthread,stdarg,stddef,stdint,inttypes,types,unistd
1633838b8255282d10af15c5c84cee5a51466712Bob Halleysys types
1633838b8255282d10af15c5c84cee5a51466712Bob Halleytyp long.double,size_t,ssize_t
1633838b8255282d10af15c5c84cee5a51466712Bob Halleytyp __va_list stdio.h
1633838b8255282d10af15c5c84cee5a51466712Bob Halley
1633838b8255282d10af15c5c84cee5a51466712Bob Halleymac SF_APPEND,SF_CLOSE sys/stat.h sys/socket.h
1633838b8255282d10af15c5c84cee5a51466712Bob Halley
1633838b8255282d10af15c5c84cee5a51466712Bob Halleydll import note{ Microsoft import/export nonsense }end execute{
1633838b8255282d10af15c5c84cee5a51466712Bob Halley __declspec(dllimport) int foo;
1633838b8255282d10af15c5c84cee5a51466712Bob Halley int main() { return foo == 5 ? 0 : 1; }
1633838b8255282d10af15c5c84cee5a51466712Bob Halley int bar = 5;
1633838b8255282d10af15c5c84cee5a51466712Bob Halley int* _imp__foo = &bar;
1633838b8255282d10af15c5c84cee5a51466712Bob Halley}end
1633838b8255282d10af15c5c84cee5a51466712Bob Halley
1633838b8255282d10af15c5c84cee5a51466712Bob Halleystd proto note{ standard C prototypes ok }end compile{
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley extern int foo(int, int);
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley bar() { foo(1, 1); }
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley}end
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halleytst ptr_void note{ standard C void* ok }end compile{
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley extern void* foo();
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley void* bar() { return foo(); }
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley}end
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley
6792dd6d22db8441bb7c4d24819b4f9291e257b1Bob Halleycat{
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley /* disable non-standard linux/gnu inlines */
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #ifdef __GNUC__
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # undef __OPTIMIZE_SIZE__
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __OPTIMIZE_SIZE__ 1
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #endif
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley
3740b569ae76295b941d57a724a43beb75b533baBob Halley /* __STD_C indicates that the language is ANSI-C or C++ */
3740b569ae76295b941d57a724a43beb75b533baBob Halley #if !defined(__STD_C) && __STDC__
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __STD_C 1
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #endif
0ab04d76c8b47210c91cb960854a17b28e2daa35Bob Halley #if !defined(__STD_C) && (__cplusplus || c_plusplus)
3740b569ae76295b941d57a724a43beb75b533baBob Halley # define __STD_C 1
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #endif
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #if !defined(__STD_C) && _std_proto
5f74ac33a07148f2f28b26870c5beccb778b4bd3Bob Halley # define __STD_C 1
b32248301c1f0c9b8ed71e1355657a5640e153f7Bob Halley #endif
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #if !defined(__STD_C)
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __STD_C 0
0ab04d76c8b47210c91cb960854a17b28e2daa35Bob Halley #endif
3740b569ae76295b941d57a724a43beb75b533baBob Halley
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley /* extern symbols must be protected against C++ name mangling */
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #ifndef _BEGIN_EXTERNS_
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # if __cplusplus || c_plusplus
5f74ac33a07148f2f28b26870c5beccb778b4bd3Bob Halley # define _BEGIN_EXTERNS_ extern "C" {
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define _END_EXTERNS_ }
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # else
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define _BEGIN_EXTERNS_
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define _END_EXTERNS_
b32248301c1f0c9b8ed71e1355657a5640e153f7Bob Halley # endif
5f74ac33a07148f2f28b26870c5beccb778b4bd3Bob Halley #endif
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley
b32248301c1f0c9b8ed71e1355657a5640e153f7Bob Halley /* _ARG_ simplifies function prototyping among flavors of C */
3740b569ae76295b941d57a724a43beb75b533baBob Halley #ifndef _ARG_
3740b569ae76295b941d57a724a43beb75b533baBob Halley # if __STD_C
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define _ARG_(x) x
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley # else
db1e643c60d9b521c421f3f528e7946dd37cacbfBob Halley # define _ARG_(x) ()
db1e643c60d9b521c421f3f528e7946dd37cacbfBob Halley # endif
db1e643c60d9b521c421f3f528e7946dd37cacbfBob Halley #endif
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley /* _NIL_ simplifies defining nil pointers to a given type */
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley #ifndef _NIL_
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley # define _NIL_(x) ((x)0)
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #endif
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley
b32248301c1f0c9b8ed71e1355657a5640e153f7Bob Halley /* __INLINE__, if defined, is the inline keyword */
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #if !defined(__INLINE__) && defined(__cplusplus)
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __INLINE__ inline
0ab04d76c8b47210c91cb960854a17b28e2daa35Bob Halley #endif
3740b569ae76295b941d57a724a43beb75b533baBob Halley #if !defined(__INLINE__) && defined(_WIN32) && !defined(__GNUC__)
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __INLINE__ __inline
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #endif
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley /* Void_t is defined so that Void_t* can address any type */
5f74ac33a07148f2f28b26870c5beccb778b4bd3Bob Halley #ifndef Void_t
5f74ac33a07148f2f28b26870c5beccb778b4bd3Bob Halley # if __STD_C
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define Void_t void
5f74ac33a07148f2f28b26870c5beccb778b4bd3Bob Halley # else
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define Void_t char
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # endif
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #endif
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley /* windows variants and veneers */
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #if !defined(_WINIX) && (_UWIN || __CYGWIN__ || __EMX__)
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define _WINIX 1
b32248301c1f0c9b8ed71e1355657a5640e153f7Bob Halley #endif
0ab04d76c8b47210c91cb960854a17b28e2daa35Bob Halley
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley /* dynamic linked library external scope handling */
b32248301c1f0c9b8ed71e1355657a5640e153f7Bob Halley #ifdef __DYNAMIC__
b32248301c1f0c9b8ed71e1355657a5640e153f7Bob Halley # undef __DYNAMIC__
0ab04d76c8b47210c91cb960854a17b28e2daa35Bob Halley # ifndef _DLL
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define _DLL 1
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # endif
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #endif
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #if _dll_import
3740b569ae76295b941d57a724a43beb75b533baBob Halley # if _BLD_STATIC && !_BLD_DLL
3740b569ae76295b941d57a724a43beb75b533baBob Halley # undef _DLL
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # else
3740b569ae76295b941d57a724a43beb75b533baBob Halley # if !_UWIN && !defined(_DLL)
3740b569ae76295b941d57a724a43beb75b533baBob Halley # define _DLL 1
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # endif
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # endif
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # if !defined(__EXPORT__) && _BLD_DLL
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __EXPORT__ __declspec(dllexport)
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # endif
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # if !defined(__IMPORT__) && ( _BLD_DLL || defined(_DLL) )
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __IMPORT__ __declspec(dllimport)
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley # endif
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley # if _BLD_DLL && _UWIN
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley # define __DYNAMIC__(v) (_ast_getdll()->_ast_ ## v)
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley # endif
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #endif
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #if !defined(_astimport)
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley # if defined(__IMPORT__) && defined(_DLL)
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley # define _astimport __IMPORT__
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley # else
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley # define _astimport extern
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley # endif
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #endif
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #if _dll_import && ( !_BLD_DLL || _WINIX && !_UWIN )
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley # ifdef __STDC__
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley # define __EXTERN__(T,obj) extern T obj; T* _imp__ ## obj = &obj
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley # define __DEFINE__(T,obj,val) T obj = val; T* _imp__ ## obj = &obj
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley # else
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley # define __EXTERN__(T,obj) extern T obj; T* _imp__/**/obj = &obj
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley # define __DEFINE__(T,obj,val) T obj = val; T* _imp__/**/obj = &obj
0ab04d76c8b47210c91cb960854a17b28e2daa35Bob Halley # endif
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #else
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __EXTERN__(T,obj) extern T obj
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __DEFINE__(T,obj,val) T obj = val
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #endif
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley}end
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley
db1e643c60d9b521c421f3f528e7946dd37cacbfBob Halleyif tst - note{ <stdarg.h>+<wchar.h> works }end compile{
db1e643c60d9b521c421f3f528e7946dd37cacbfBob Halley /*<NOSTDIO>*/
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley #include <stdarg.h>
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley #include <wchar.h>
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley }end
db1e643c60d9b521c421f3f528e7946dd37cacbfBob Halleyelif tst - note{ explicit <sys/va_list.h> before <stdarg.h>+<wchar.h> }end compile{
db1e643c60d9b521c421f3f528e7946dd37cacbfBob Halley /*<NOSTDIO>*/
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley #include <sys/va_list.h>
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley #include <stdarg.h>
5f74ac33a07148f2f28b26870c5beccb778b4bd3Bob Halley #include <wchar.h>
db1e643c60d9b521c421f3f528e7946dd37cacbfBob Halley }end {
db1e643c60d9b521c421f3f528e7946dd37cacbfBob Halley #include <sys/va_list.h>
db1e643c60d9b521c421f3f528e7946dd37cacbfBob Halley }
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halleyendif
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halleytst ast_LL note{ LL numeric suffix supported }end compile{
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley int i = 1LL;
c92ba071011bbc09e7146729606fd9e89a9be02cBob Halley unsigned int u = 1ULL; /* NOTE: some compilers choke on 1LLU */
c92ba071011bbc09e7146729606fd9e89a9be02cBob Halley}end
c92ba071011bbc09e7146729606fd9e89a9be02cBob Halley
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halleytst - -DN=1 - -DN=2 - -DN=3 - -DN=4 - -DN=5 - -DN=6 - -DN=7 - -DN=8 - -DN=0 output{
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #define _BYTESEX_H
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley
5f74ac33a07148f2f28b26870c5beccb778b4bd3Bob Halley #include <string.h>
5f74ac33a07148f2f28b26870c5beccb778b4bd3Bob Halley #include <sys/types.h>
5f74ac33a07148f2f28b26870c5beccb778b4bd3Bob Halley
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #if _STD_
5f74ac33a07148f2f28b26870c5beccb778b4bd3Bob Halley #if N == 1
c92ba071011bbc09e7146729606fd9e89a9be02cBob Halley #define _ast_int8_t long
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #define _ast_int8_str "long"
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #endif
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #if N == 2
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #define _ast_int8_t long long
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #define _ast_int8_str "long long"
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #endif
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #if N == 3
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #define _ast_int8_t __int64
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #define _ast_int8_str "__int64"
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #endif
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #if N == 4
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #define _ast_int8_t __int64_t
#define _ast_int8_str "__int64_t"
#endif
#if N == 5
#define _ast_int8_t _int64_t
#define _ast_int8_str "_int64_t"
#endif
#if N == 6
#define _ast_int8_t int64_t
#define _ast_int8_str "int64_t"
#endif
#if N == 7
#define _ast_int8_t _int64
#define _ast_int8_str "_int64"
#endif
#if N == 8
#define _ast_int8_t int64
#define _ast_int8_str "int64"
#endif
#endif
#define elementsof(x) (sizeof(x)/sizeof(x[0]))
static char i_char = 1;
static short i_short = 1;
static int i_int = 1;
static long i_long = 1L;
#ifdef _ast_int8_t
#if _ast_LL
static _ast_int8_t i_long_long = 1LL;
static unsigned _ast_int8_t u_long_long = 18446744073709551615ULL;
#else
static _ast_int8_t i_long_long = 1;
static unsigned _ast_int8_t u_long_long = 18446744073709551615;
#endif
#endif
static struct
{
char* name;
int size;
char* swap;
} int_type[] =
{
"char", sizeof(char), (char*)&i_char,
"short", sizeof(short), (char*)&i_short,
"int", sizeof(int), (char*)&i_int,
"long", sizeof(long), (char*)&i_long,
#ifdef _ast_int8_t
_ast_int8_str, sizeof(_ast_int8_t), (char*)&i_long_long,
#endif
};
static int int_size[] = { 1, 2, 4, 8 };
int
main()
{
register int t;
register int s;
register int m = 1;
register int b = 1;
register int w = 0;
#ifdef _ast_int8_t
unsigned _ast_int8_t p;
char buf[64];
if (int_type[elementsof(int_type)-1].size <= 4)
return 1;
p = 0x12345678;
p <<= 32;
p |= 0x9abcdef0;
sprintf(buf, "0x%016llx", p);
if (strcmp(buf, "0x123456789abcdef0"))
return 1;
#endif
for (s = 0; s < elementsof(int_size); s++)
{
for (t = 0; t < elementsof(int_type) && int_type[t].size < int_size[s]; t++);
if (t < elementsof(int_type))
{
m = int_size[s];
#if __INTERIX
if (m == 8)
{
printf("#ifdef _MSC_VER\n");
printf("#define _ast_int8_t __int64\n");
printf("#else\n");
printf("#define _ast_int8_t long long\n");
printf("#endif\n");
}
else
#endif
printf("#define _ast_int%d_t %s\n", m, int_type[t].name);
if (m > 1)
{
if (*int_type[t].swap)
w |= b;
b <<= 1;
}
}
}
printf("#define _ast_intmax_t _ast_int%d_t\n", m);
if (m == sizeof(long))
printf("#define _ast_intmax_long 1\n");
printf("#define _ast_intswap %d\n", w);
printf("\n");
return 0;
}
}end
tst - output{
#include <string.h>
#include <sys/types.h>
#if _X86_ || _X64_
#define COND 1
#define CONDNAME "_X64_"
#else
#define COND 0
#endif
#define elementsof(x) (sizeof(x)/sizeof(x[0]))
static struct
{
char* name;
int size;
int cond;
} types[] =
{
"short", sizeof(short), 0,
"int", sizeof(int), 0,
"long", sizeof(long), 0,
"size_t", sizeof(size_t), 0,
"pointer", sizeof(void*), COND * 4,
"float", sizeof(float), 0,
"double", sizeof(double), 0,
#ifdef _typ_long_double
"long_double", sizeof(long double), 0,
#endif
};
int
main()
{
register int t;
for (t = 0; t < elementsof(types); t++)
#if COND
if (types[t].cond)
{
printf("#if %s\n", CONDNAME);
printf("#define _ast_sizeof_%s%s %d /* sizeof(%s) */\n", types[t].name, strlen(types[t].name) < 4 ? "\t" : "", types[t].cond * 2, types[t].name);
printf("#else\n");
printf("#define _ast_sizeof_%s%s %d /* sizeof(%s) */\n", types[t].name, strlen(types[t].name) < 4 ? "\t" : "", types[t].cond, types[t].name);
printf("#endif\n");
}
else
#endif
printf("#define _ast_sizeof_%s%s %d /* sizeof(%s) */\n", types[t].name, strlen(types[t].name) < 4 ? "\t" : "", types[t].size, types[t].name);
printf("\n");
return 0;
}
}end
tst - -DN=1 - -DN=0 output{
#define _BYTESEX_H
#include <string.h>
#include <sys/types.h>
#if !N || !_STD_
#undef _typ_long_double
#endif
#define elementsof(x) (sizeof(x)/sizeof(x[0]))
static struct
{
char* name;
int size;
} flt_type[] =
{
"float", sizeof(float),
"double", sizeof(double),
#ifdef _typ_long_double
"long double", sizeof(long double),
#endif
};
int
main()
{
register int t;
register int m = 1;
#ifdef _typ_long_double
long double p;
char buf[64];
if (flt_type[elementsof(flt_type)-1].size <= sizeof(double))
return 1;
p = 1.12345E-55;
sprintf(buf, "%1.5LE", p);
if (strcmp(buf, "1.12345E-55"))
return 1;
#endif
for (t = 0; t < elementsof(flt_type); t++)
{
while (t < (elementsof(flt_type) - 1) && flt_type[t].size == flt_type[t + 1].size)
t++;
m = flt_type[t].size;
printf("#define _ast_flt%d_t %s\n", flt_type[t].size, flt_type[t].name);
}
printf("#define _ast_fltmax_t _ast_flt%d_t\n", m);
if (m == sizeof(double))
printf("#define _ast_fltmax_double 1\n");
return 0;
}
}end
typ int8_t stdint.h inttypes.h no{
#undef _typ_int8_t
#define _typ_int8_t 1
typedef _ast_int1_t int8_t;
}end
typ uint8_t stdint.h inttypes.h no{
#undef _typ_uint8_t
#define _typ_uint8_t 1
typedef unsigned _ast_int1_t uint8_t;
}end
typ int16_t stdint.h inttypes.h no{
#undef _typ_int16_t
#define _typ_int16_t 1
typedef _ast_int2_t int16_t;
}end
typ uint16_t stdint.h inttypes.h no{
#undef _typ_uint16_t
#define _typ_uint16_t 1
typedef unsigned _ast_int2_t uint16_t;
}end
typ int32_t stdint.h inttypes.h no{
#undef _typ_int32_t
#define _typ_int32_t 1
typedef _ast_int4_t int32_t;
}end
typ uint32_t stdint.h inttypes.h no{
#undef _typ_uint32_t
#define _typ_uint32_t 1
typedef unsigned _ast_int4_t uint32_t;
}end
typ int64_t stdint.h inttypes.h no{
#ifdef _ast_int8_t
#undef _typ_int64_t
#define _typ_int64_t 1
typedef _ast_int8_t int64_t;
#endif
}end
typ uint64_t stdint.h inttypes.h no{
#ifdef _ast_int8_t
#undef _typ_uint64_t
#define _typ_uint64_t 1
typedef unsigned _ast_int8_t uint64_t;
#endif
}end
typ intmax_t stdint.h inttypes.h no{
#undef _typ_intmax_t
#define _typ_intmax_t 1
typedef _ast_intmax_t intmax_t;
}end
typ uintmax_t stdint.h inttypes.h no{
#undef _typ_uintmax_t
#define _typ_uintmax_t 1
typedef unsigned _ast_intmax_t uintmax_t;
}end
typ uintptr_t stdint.h inttypes.h no{
#undef _typ_uintptr_t
#define _typ_uintptr_t 1
#if _ast_sizeof_pointer == 8 && defined(_ast_int8_t)
typedef unsigned _ast_int8_t uintptr_t;
#else
typedef unsigned _ast_int4_t uintptr_t;
#endif
}end
tst - -DTRY=1 - -DTRY=1 -Dvoid=char - -DTRY=2 - -DTRY=3 - -DTRY=4 output{
#if _STD_ && _hdr_stdarg
#include <stdarg.h>
static void
varyfunny(int* p, ...)
{
va_list ap;
va_start(ap, p);
#if TRY == 1
*p = *ap++ != 0;
#endif /*TRY == 1*/
#if TRY == 2
*p = *ap != 0;
#endif /*TRY == 2*/
#if TRY == 3
*p = ap++ != 0;
#endif /*TRY == 3*/
va_end(ap);
}
#else
#include <varargs.h>
static void
varyfunny(va_alist)
va_dcl
{
va_list ap;
int* p;
va_start(ap);
p = va_arg(ap, int*);
#if TRY == 1
*p = *ap++ != 0;
#endif /*TRY == 1*/
#if TRY == 2
*p = *ap != 0;
#endif /*TRY == 2*/
#if TRY == 3
*p = ap++ != 0;
#endif /*TRY == 3*/
va_end(ap);
}
#endif
int
main()
{
int r;
printf("\n#ifndef va_listref\n");
printf("#ifndef va_start\n");
printf("#if __STD_C\n");
printf("#include <stdarg.h>\n");
printf("#else\n");
printf("#include <varargs.h>\n");
printf("#endif\n");
printf("#endif\n");
#if TRY == 4
printf("#define va_listref(p) (&(p))\t");
printf("/* pass va_list to varargs function */\n");
printf("#define va_listval(p) (*(p))\t");
printf("/* retrieve va_list from va_arg(ap,va_listarg) */\n");
printf("#define va_listarg va_list*\t");
printf("/* va_arg() va_list type */\n");
#else
varyfunny(&r);
printf("#define va_listref(p) (p)\t");
printf("/* pass va_list to varargs function */\n");
if (sizeof(va_list) > sizeof(void*))
printf("#define va_listval(p) (*(p))\t");
else
printf("#define va_listval(p) (p)\t");
printf("/* retrieve va_list from va_arg(ap,va_listarg) */\n");
#if TRY == 2
printf("#define va_listarg va_list*\t");
#else
printf("#define va_listarg va_list\t");
#endif /*TRY == 2*/
printf("/* va_arg() va_list type */\n");
#endif /*TRY == 4*/
#if _UWIN
printf("#ifndef va_copy\n");
printf("#define va_copy(to,fr) ((to)=(fr))\t");
printf("/* copy va_list fr -> to */\n");
printf("#endif\n");
#else
#if !defined(va_copy)
#if defined(__va_copy)
printf("#ifndef va_copy\n");
printf("#define va_copy(to,fr) __va_copy(to,fr)\t");
printf("/* copy va_list fr -> to */\n");
printf("#endif\n");
#else
#if TRY == 2
printf("#ifndef va_copy\n");
printf("#define va_copy(to,fr) memcpy(to,fr,sizeof(va_list))\t");
printf("/* copy va_list fr -> to */\n");
printf("#endif\n");
#else
printf("#ifndef va_copy\n");
printf("#define va_copy(to,fr) ((to)=(fr))\t");
printf("/* copy va_list fr -> to */\n");
printf("#endif\n");
#endif
#endif
#endif
#endif
printf("#endif\n");
return 0;
}
}end
cat{
#ifndef _AST_STD_H
# if __STD_C && _hdr_stddef
# include <stddef.h>
# endif
# if _sys_types
# include <sys/types.h>
# endif
# if _hdr_stdint
# include <stdint.h>
# else
# if _hdr_inttypes
# include <inttypes.h>
# endif
# endif
#endif
#if !_typ_size_t
# define _typ_size_t 1
typedef int size_t;
#endif
#if !_typ_ssize_t
# define _typ_ssize_t 1
typedef int ssize_t;
#endif
#ifndef _AST_STD_H
# define _def_map_ast 1
# if !_def_map_ast
# include <ast_map.h>
# endif
#endif
}end
run{
grep __NO_INCLUDE_WARN__ /usr/include/stat.h >/dev/null 2>&1 &&
grep '<name.h>' /usr/include/sys/stat.h >/dev/null 2>&1 &&
grep __name_h /usr/include/name.h >/dev/null 2>&1 &&
cat <<!
/* disable ${HOSTTYPE} <sys/foo.h> vs. <foo.h> clash warnings */
#ifndef __NO_INCLUDE_WARN__
#define __NO_INCLUDE_WARN__ 1
#endif
/* disable ${HOSTTYPE} <sys/stat.h> <name.h> hijack */
#ifndef __name_h
#define __name_h 1
#endif
!
}end