1# Copyright (C) 2002-2004, 2006-2018 Free Software Foundation, Inc. 2# This file is free software; the Free Software Foundation 3# gives unlimited permission to copy and/or distribute it, 4# with or without modifications, as long as this notice is preserved. 5 6# Test whether the *printf family of functions supports the 'a' and 'A' 7# conversion specifier for hexadecimal output of floating-point numbers. 8# (ISO C99, POSIX:2001) 9# Result is gl_cv_func_printf_directive_a. 10 11printf_directive_a_test = ''' 12#include <stdio.h> 13#include <string.h> 14static char buf[100]; 15static double zero = 0.0; 16int main () 17{ 18 int result = 0; 19 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0 20 || (strcmp (buf, "0x1.922p+1 33") != 0 21 && strcmp (buf, "0x3.244p+0 33") != 0 22 && strcmp (buf, "0x6.488p-1 33") != 0 23 && strcmp (buf, "0xc.91p-2 33") != 0)) 24 result |= 1; 25 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0 26 || (strcmp (buf, "-0X1.922P+1 33") != 0 27 && strcmp (buf, "-0X3.244P+0 33") != 0 28 && strcmp (buf, "-0X6.488P-1 33") != 0 29 && strcmp (buf, "-0XC.91P-2 33") != 0)) 30 result |= 2; 31 /* This catches a FreeBSD 6.1 bug: it doesn't round. */ 32 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0 33 || (strcmp (buf, "0x1.83p+0 33") != 0 34 && strcmp (buf, "0x3.05p-1 33") != 0 35 && strcmp (buf, "0x6.0ap-2 33") != 0 36 && strcmp (buf, "0xc.14p-3 33") != 0)) 37 result |= 4; 38 /* This catches a Mac OS X 10.12.4 (Darwin 16.5) bug: it doesn't round. */ 39 if (sprintf (buf, "%.0a %d", 1.51, 33, 44, 55) < 0 40 || (strcmp (buf, "0x2p+0 33") != 0 41 && strcmp (buf, "0x3p-1 33") != 0 42 && strcmp (buf, "0x6p-2 33") != 0 43 && strcmp (buf, "0xcp-3 33") != 0)) 44 result |= 4; 45 /* This catches a FreeBSD 6.1 bug. See 46 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */ 47 if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0 48 || buf[0] == '0') 49 result |= 8; 50 /* This catches a Mac OS X 10.3.9 (Darwin 7.9) bug. */ 51 if (sprintf (buf, "%.1a", 1.999) < 0 52 || (strcmp (buf, "0x1.0p+1") != 0 53 && strcmp (buf, "0x2.0p+0") != 0 54 && strcmp (buf, "0x4.0p-1") != 0 55 && strcmp (buf, "0x8.0p-2") != 0)) 56 result |= 16; 57 /* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a 58 glibc 2.4 bug <https://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */ 59 if (sprintf (buf, "%.1La", 1.999L) < 0 60 || (strcmp (buf, "0x1.0p+1") != 0 61 && strcmp (buf, "0x2.0p+0") != 0 62 && strcmp (buf, "0x4.0p-1") != 0 63 && strcmp (buf, "0x8.0p-2") != 0)) 64 result |= 32; 65 return result; 66} 67''' 68 69glibc_printf_directive_a_test = ''' 70#include <features.h> 71#ifdef __GNU_LIBRARY__ 72 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)) && !defined __UCLIBC__ 73 #else 74 #error Too old glibc 75 #endif 76#else 77 #error Not glibc 78#endif 79int main () { return 0; } 80''' 81 82if not meson.is_cross_build() or meson.has_exe_wrapper() 83 run_result = cc.run(printf_directive_a_test, 84 name : 'printf supports the \'a\' and \'A\' directives') 85 gl_cv_func_printf_directive_a = run_result.compiled() and run_result.returncode() == 0 86else 87 if host_system == 'linux' 88 gl_cv_func_printf_directive_a = cc.compiles(glibc_printf_directive_a_test) 89 elif host_system == 'windows' 90 gl_cv_func_printf_directive_a = false 91 else 92 gl_cv_func_printf_directive_a = false 93 endif 94endif 95