1*c87b03e5Sespie /* Format checking tests: common header. */ 2*c87b03e5Sespie /* Origin: Joseph Myers <jsm28@cam.ac.uk> */ 3*c87b03e5Sespie 4*c87b03e5Sespie #include <stdarg.h> 5*c87b03e5Sespie #include <stddef.h> 6*c87b03e5Sespie 7*c87b03e5Sespie #ifndef _WINT_T 8*c87b03e5Sespie #ifndef __WINT_TYPE__ 9*c87b03e5Sespie #define __WINT_TYPE__ unsigned int 10*c87b03e5Sespie #endif 11*c87b03e5Sespie typedef __WINT_TYPE__ wint_t; 12*c87b03e5Sespie #endif 13*c87b03e5Sespie 14*c87b03e5Sespie /* Kludges to get types corresponding to size_t and ptrdiff_t. */ 15*c87b03e5Sespie #define unsigned signed 16*c87b03e5Sespie typedef __SIZE_TYPE__ signed_size_t; 17*c87b03e5Sespie /* We also use this type to approximate ssize_t. */ 18*c87b03e5Sespie typedef __SIZE_TYPE__ ssize_t; 19*c87b03e5Sespie #undef unsigned 20*c87b03e5Sespie #define signed /* Type might or might not have explicit 'signed'. */ 21*c87b03e5Sespie typedef unsigned __PTRDIFF_TYPE__ unsigned_ptrdiff_t; 22*c87b03e5Sespie #undef signed 23*c87b03e5Sespie 24*c87b03e5Sespie __extension__ typedef long long int llong; 25*c87b03e5Sespie __extension__ typedef unsigned long long int ullong; 26*c87b03e5Sespie 27*c87b03e5Sespie /* %q formats want a "quad"; GCC considers this to be a long long. */ 28*c87b03e5Sespie typedef llong quad_t; 29*c87b03e5Sespie typedef ullong u_quad_t; 30*c87b03e5Sespie 31*c87b03e5Sespie /* This next definition is a kludge. When GCC has a <stdint.h> it 32*c87b03e5Sespie should be used. 33*c87b03e5Sespie */ 34*c87b03e5Sespie /* (T *) if E is zero, (void *) otherwise. */ 35*c87b03e5Sespie #define type_if_not(T, E) __typeof__(0 ? (T *)0 : (void *)(E)) 36*c87b03e5Sespie 37*c87b03e5Sespie /* (T *) if E is nonzero, (void *) otherwise. */ 38*c87b03e5Sespie #define type_if(T, E) type_if_not(T, !(E)) 39*c87b03e5Sespie 40*c87b03e5Sespie /* Combine pointer types, all but one (void *). */ 41*c87b03e5Sespie #define type_comb2(T1, T2) __typeof__(0 ? (T1)0 : (T2)0) 42*c87b03e5Sespie #define type_comb3(T1, T2, T3) type_comb2(T1, type_comb2(T2, T3)) 43*c87b03e5Sespie 44*c87b03e5Sespie #define maybe_int_ptr type_if(int, sizeof(int) == sizeof(llong)) 45*c87b03e5Sespie #define maybe_uint_ptr type_if(unsigned int, sizeof(unsigned int) == sizeof(ullong)) 46*c87b03e5Sespie #define maybe_long_ptr type_if(long, sizeof(long) == sizeof(llong) && sizeof(long) > sizeof(int)) 47*c87b03e5Sespie #define maybe_ulong_ptr type_if(unsigned long, sizeof(unsigned long) == sizeof(ullong) && sizeof(unsigned long) > sizeof(unsigned int)) 48*c87b03e5Sespie #define maybe_long_long_ptr type_if(llong, sizeof(llong) > sizeof(long)) 49*c87b03e5Sespie #define maybe_ulong_long_ptr type_if(ullong, sizeof(ullong) > sizeof(unsigned long)) 50*c87b03e5Sespie 51*c87b03e5Sespie #define intmax_type_ptr type_comb3(maybe_int_ptr, maybe_long_ptr, maybe_long_long_ptr) 52*c87b03e5Sespie #define uintmax_type_ptr type_comb3(maybe_uint_ptr, maybe_ulong_ptr, maybe_ulong_long_ptr) 53*c87b03e5Sespie 54*c87b03e5Sespie typedef __typeof__(*((intmax_type_ptr)0)) intmax_t; 55*c87b03e5Sespie typedef __typeof__(*((uintmax_type_ptr)0)) uintmax_t; 56*c87b03e5Sespie 57*c87b03e5Sespie #if __STDC_VERSION__ < 199901L 58*c87b03e5Sespie #define restrict /* "restrict" not in old C standard. */ 59*c87b03e5Sespie #endif 60*c87b03e5Sespie 61*c87b03e5Sespie /* This may not be correct in the particular case, but allows the 62*c87b03e5Sespie prototypes to be declared, and we don't try to link. 63*c87b03e5Sespie */ 64*c87b03e5Sespie typedef struct _FILE FILE; 65*c87b03e5Sespie extern FILE *stdin; 66*c87b03e5Sespie extern FILE *stdout; 67*c87b03e5Sespie 68*c87b03e5Sespie extern int fprintf (FILE *restrict, const char *restrict, ...); 69*c87b03e5Sespie extern int printf (const char *restrict, ...); 70*c87b03e5Sespie extern int fprintf_unlocked (FILE *restrict, const char *restrict, ...); 71*c87b03e5Sespie extern int printf_unlocked (const char *restrict, ...); 72*c87b03e5Sespie extern int sprintf (char *restrict, const char *restrict, ...); 73*c87b03e5Sespie extern int vfprintf (FILE *restrict, const char *restrict, va_list); 74*c87b03e5Sespie extern int vprintf (const char *restrict, va_list); 75*c87b03e5Sespie extern int vsprintf (char *restrict, const char *restrict, va_list); 76*c87b03e5Sespie extern int snprintf (char *restrict, size_t, const char *restrict, ...); 77*c87b03e5Sespie extern int vsnprintf (char *restrict, size_t, const char *restrict, va_list); 78*c87b03e5Sespie 79*c87b03e5Sespie extern int fscanf (FILE *restrict, const char *restrict, ...); 80*c87b03e5Sespie extern int scanf (const char *restrict, ...); 81*c87b03e5Sespie extern int sscanf (const char *restrict, const char *restrict, ...); 82*c87b03e5Sespie extern int vfscanf (FILE *restrict, const char *restrict, va_list); 83*c87b03e5Sespie extern int vscanf (const char *restrict, va_list); 84*c87b03e5Sespie extern int vsscanf (const char *restrict, const char *restrict, va_list); 85*c87b03e5Sespie 86*c87b03e5Sespie extern char *gettext (const char *); 87*c87b03e5Sespie extern char *dgettext (const char *, const char *); 88*c87b03e5Sespie extern char *dcgettext (const char *, const char *, int); 89*c87b03e5Sespie 90*c87b03e5Sespie struct tm; 91*c87b03e5Sespie 92*c87b03e5Sespie extern size_t strftime (char *restrict, size_t, const char *restrict, 93*c87b03e5Sespie const struct tm *restrict); 94*c87b03e5Sespie 95*c87b03e5Sespie extern ssize_t strfmon (char *restrict, size_t, const char *restrict, ...); 96