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 %ls format 7# directive and in particular, when a precision is specified, whether 8# the functions stop converting the wide string argument when the number 9# of bytes that have been produced by this conversion equals or exceeds 10# the precision. 11# Result is gl_cv_func_printf_directive_ls. 12 13printf_directive_ls_test = ''' 14/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before 15 <wchar.h>. 16 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be 17 included before <wchar.h>. */ 18#include <stddef.h> 19#include <stdio.h> 20#include <time.h> 21#include <wchar.h> 22#include <string.h> 23int main () 24{ 25 int result = 0; 26 char buf[100]; 27 /* Test whether %ls works at all. 28 This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on 29 Cygwin 1.5. */ 30 { 31 static const wchar_t wstring[] = { 'a', 'b', 'c', 0 }; 32 buf[0] = '\0'; 33 if (sprintf (buf, "%ls", wstring) < 0 34 || strcmp (buf, "abc") != 0) 35 result |= 1; 36 } 37 /* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an 38 assertion failure inside libc), but not on OpenBSD 4.0. */ 39 { 40 static const wchar_t wstring[] = { 'a', 0 }; 41 buf[0] = '\0'; 42 if (sprintf (buf, "%ls", wstring) < 0 43 || strcmp (buf, "a") != 0) 44 result |= 2; 45 } 46 /* Test whether precisions in %ls are supported as specified in ISO C 99 47 section 7.19.6.1: 48 "If a precision is specified, no more than that many bytes are written 49 (including shift sequences, if any), and the array shall contain a 50 null wide character if, to equal the multibyte character sequence 51 length given by the precision, the function would need to access a 52 wide character one past the end of the array." 53 This test fails on Solaris 10. */ 54 { 55 static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 }; 56 buf[0] = '\0'; 57 if (sprintf (buf, "%.2ls", wstring) < 0 58 || strcmp (buf, "ab") != 0) 59 result |= 8; 60 } 61 return result; 62} 63''' 64 65if not meson.is_cross_build() or meson.has_exe_wrapper() 66 run_result = cc.run(printf_directive_ls_test, 67 name : 'printf supports the \'ls\' directive') 68 gl_cv_func_printf_directive_ls = run_result.compiled() and run_result.returncode() == 0 69else 70 if (host_system.startswith ('openbsd') or 71 host_system.startswith ('irix') or 72 host_system.startswith ('solaris') or 73 host_system.startswith ('cygwin') or 74 host_system.startswith ('beos') or 75 host_system.startswith ('haiku')) 76 gl_cv_func_printf_directive_ls = false 77 elif host_system == 'windows' 78 gl_cv_func_printf_directive_ls = true 79 else 80 gl_cv_func_printf_directive_ls = true 81 endif 82endif 83