From f35c4d5d424071351bbf7d4e5146353be6d973bb Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 29 Aug 2018 11:57:44 +0100 Subject: [PATCH] build: Check for Unix98 positional parameter support in printf() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is equivalent to the AC_FUNC_PRINTF_UNIX98 macro which we use in configure.ac. There may still be some obscure Unix platforms which don’t natively support positional parameters, 20 years on. Signed-off-by: Philip Withnall https://gitlab.gnome.org/GNOME/glib/issues/1313 --- meson.build | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/meson.build b/meson.build index aa7d8e4f7..770ddcc4d 100644 --- a/meson.build +++ b/meson.build @@ -739,12 +739,14 @@ if cc.compiles('''#include endif # Check whether there is a vsnprintf() function with C99 semantics installed. -# AC_FUNC_VSNPRINTF_C99 +# (similar tests to AC_FUNC_VSNPRINTF_C99) # Check whether there is a snprintf() function with C99 semantics installed. -# AC_FUNC_SNPRINTF_C99 - +# (similar tests to AC_FUNC_SNPRINTF_C99) +# Check whether there is a printf() function with Unix98 semantics installed. +# (similar tests to AC_FUNC_PRINTF_UNIX98) have_good_vsnprintf = false have_good_snprintf = false +have_good_printf = false if host_system == 'windows' and cc.get_id() == 'msvc' # Unfortunately the Visual Studio 2015+ implementations of C99-style @@ -755,6 +757,7 @@ if host_system == 'windows' and cc.get_id() == 'msvc' # rigorous enough to notice, though. glib_conf.set('HAVE_C99_SNPRINTF', false) glib_conf.set('HAVE_C99_VSNPRINTF', false) + glib_conf.set('HAVE_UNIX98_PRINTF', false) else vsnprintf_c99_test_code = ''' #include @@ -851,6 +854,31 @@ main(void) have_good_snprintf = meson.get_cross_property('have_c99_snprintf', false) glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf) endif + + printf_unix98_test_code = ''' +#include + +int +main (void) +{ + char buffer[128]; + + sprintf (buffer, "%2\$d %3\$d %1\$d", 1, 2, 3); + if (strcmp ("2 3 1", buffer) == 0) + exit (0); + exit (1); +}''' + + if cc_can_run + rres = cc.run(printf_unix98_test_code, name : 'Unix98 printf positional parameters') + if rres.compiled() and rres.returncode() == 0 + glib_conf.set('HAVE_UNIX98_PRINTF', 1) + have_good_printf = true + endif + else + have_good_printf = meson.get_cross_property('have_unix98_printf', false) + glib_conf.set('HAVE_UNIX98_PRINTF', have_good_printf) + endif endif if host_system == 'windows' @@ -859,9 +887,9 @@ else glib_conf.set('EXEEXT', '') endif -if have_good_vsnprintf and have_good_snprintf - # Our printf is 'good' only if vsnpintf()/snprintf() supports C99 well enough - glib_conf.set('HAVE_GOOD_PRINTF', 1) # FIXME: Check for HAVE_UNIX98_PRINTF? +if have_good_vsnprintf and have_good_snprintf and have_good_printf + # Our printf is 'good' only if vsnpintf()/snprintf()/printf() supports C99 well enough + glib_conf.set('HAVE_GOOD_PRINTF', 1) else glib_conf.set('HAVE_VASPRINTF', 1) endif