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 large precisions. 7# On mingw, precisions larger than 512 are treated like 512, in integer, 8# floating-point or pointer output. On Solaris 10/x86, precisions larger 9# than 510 in floating-point output crash the program. On Solaris 10/SPARC, 10# precisions larger than 510 in floating-point output yield wrong results. 11# On AIX 7.1, precisions larger than 998 in floating-point output yield 12# wrong results. On BeOS, precisions larger than 1044 crash the program. 13# Result is gl_cv_func_printf_precision. 14 15printf_precision_test = ''' 16#include <stdio.h> 17#include <string.h> 18static char buf[5000]; 19int main () 20{ 21 int result = 0; 22#ifdef __BEOS__ 23 /* On BeOS, this would crash and show a dialog box. Avoid the crash. */ 24 return 1; 25#endif 26 if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3) 27 result |= 1; 28 if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5) 29 result |= 2; 30 if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5 31 || buf[0] != '1') 32 result |= 4; 33 if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5 34 || buf[0] != '1') 35 result |= 4; 36 return result; 37} 38''' 39 40if not meson.is_cross_build() or meson.has_exe_wrapper() 41 run_result = cc.run(printf_precision_test, 42 name : 'printf supports large precisions') 43 gl_cv_func_printf_precision = run_result.compiled() and run_result.returncode() == 0 44else 45 gl_cv_func_printf_precision = true 46 # Guess no only on Solaris, native Windows, and BeOS systems. 47 if (host_system == 'windows' or 48 host_system == 'beos' or 49 host_system == 'haiku' or 50 host_system == 'sunos' or 51 host_system == 'solaris') 52 gl_cv_func_printf_precision = false 53 endif 54endif 55