Thomas Haller 5525672a5f build: avoid "-Werror=format-extra-args" warnings in detecting printf for gnulib
Otherwise, `CFLAGS='-Wall -Werror' meson build` fails detection with:

  Running compile:
  Working directory:  /data/src/glib/build/meson-private/tmpoozk2y4b
  Code:

  #include <stdio.h>
  #include <string.h>
  static char buf[100];
  static double zero = 0.0;
  int main ()
  {
    if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
        || (strcmp (buf, "       inf") != 0
            && strcmp (buf, "  infinity") != 0))
      return 1;
    return 0;
  }

  -----------
  Command line: `cc /data/src/glib/build/meson-private/tmpoozk2y4b/testfile.c -o /data/src/glib/build/meson-private/tmpoozk2y4b/output.exe -Werror -Wall -D_FILE_OFFSET_BITS=64 -O0 -std=gnu99` -> 1
  stderr:
  /data/src/glib/build/meson-private/tmpoozk2y4b/testfile.c: In function 'main':
  /data/src/glib/build/meson-private/tmpoozk2y4b/testfile.c:8:21: error: too many arguments for format [-Werror=format-extra-args]
      8 |   if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
        |                     ^~~~~~~
  cc1: all warnings being treated as errors
  -----------
  Could not compile test file /data/src/glib/build/meson-private/tmpoozk2y4b/testfile.c: 1

  Checking if "printf supports the zero flag correctly" runs: DID NOT COMPILE
2024-02-07 20:40:59 +01:00

41 lines
1.3 KiB
Meson

# Copyright (C) 2002-2004, 2006-2018 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# Test whether the *printf family of functions supports padding of non-finite
# values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
# <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html>
# Result is gl_cv_func_printf_flag_zero.
printf_flag_zero_test = '''
#include <stdio.h>
#include <string.h>
static char buf[100];
static double zero = 0.0;
int main ()
{
if (sprintf (buf, "%010f", 1.0 / zero) < 0
|| (strcmp (buf, " inf") != 0
&& strcmp (buf, " infinity") != 0))
return 1;
return 0;
}
'''
if meson.can_run_host_binaries()
run_result = cc.run(printf_flag_zero_test,
name : 'printf supports the zero flag correctly')
gl_cv_func_printf_flag_zero = run_result.compiled() and run_result.returncode() == 0
else
if host_system in ['linux', 'android']
gl_cv_func_printf_flag_zero = true
elif host_system.startswith ('beos')
gl_cv_func_printf_flag_zero = true
elif host_system == 'windows'
gl_cv_func_printf_flag_zero = false
else
gl_cv_func_printf_flag_zero = false
endif
endif