Skip to content

Commit 3e12cac

Browse files
committed
Better test for cross-compiling when checking for C99 snprintf
We want to avoid calling AX_FUNC_SNPRINTF entirely if cross-compiling since it is not possible to undo the setting of PREFER_PORTABLE_SNPRINTF. The previous attempt to do this failed to take into account that PREFER_PORTABLE_SNPRINTF would still be defined. GitHub issue #969
1 parent 4751a4d commit 3e12cac

2 files changed

Lines changed: 34 additions & 20 deletions

File tree

configure

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24790,7 +24790,31 @@ esac
2479024790
COMPAT_TEST_PROGS="${COMPAT_TEST_PROGS}${COMPAT_TEST_PROGS+ }mktemp_test"
2479124791

2479224792
fi
24793-
ac_fn_c_check_func "$LINENO" "snprintf" "ac_cv_func_snprintf"
24793+
if test X"$ac_cv_build_prog_cc_c99" != X"no" -a X"$cross_compiling" = X"yes"
24794+
then :
24795+
24796+
# If we have a C99 compiler and are cross-compiling, assume
24797+
# C99-compliant v?snprintf().
24798+
ac_fn_c_check_func "$LINENO" "snprintf" "ac_cv_func_snprintf"
24799+
if test "x$ac_cv_func_snprintf" = xyes
24800+
then :
24801+
printf "%s\n" "#define HAVE_SNPRINTF 1" >>confdefs.h
24802+
24803+
fi
24804+
ac_fn_c_check_func "$LINENO" "vsnprintf" "ac_cv_func_vsnprintf"
24805+
if test "x$ac_cv_func_vsnprintf" = xyes
24806+
then :
24807+
printf "%s\n" "#define HAVE_VSNPRINTF 1" >>confdefs.h
24808+
24809+
fi
24810+
24811+
ac_cv_have_working_snprintf="$ac_cv_func_snprintf"
24812+
ac_cv_have_working_vsnprintf="$ac_cv_func_vsnprintf"
24813+
24814+
else case e in #(
24815+
e)
24816+
# Check for C99-compliant v?snprintf().
24817+
ac_fn_c_check_func "$LINENO" "snprintf" "ac_cv_func_snprintf"
2479424818
if test "x$ac_cv_func_snprintf" = xyes
2479524819
then :
2479624820
printf "%s\n" "#define HAVE_SNPRINTF 1" >>confdefs.h
@@ -24919,19 +24943,8 @@ printf "%s\n" "$as_me: WARNING: Replacing missing/broken (v)snprintf() with sudo
2491924943
printf "%s\n" "#define PREFER_PORTABLE_SNPRINTF 1" >>confdefs.h
2492024944

2492124945
fi
24922-
if test X"$ac_cv_build_prog_cc_c99" != X"no"
24923-
then :
24924-
24925-
# If we have a C99 compiler and are cross-compiling, assume
24926-
# C99-compliant v?snprintf().
24927-
if test X"$ac_cv_have_working_snprintf$ac_cv_have_working_vsnprintf" = X"crosscross"
24928-
then :
24929-
24930-
ac_cv_have_working_snprintf=yes
24931-
ac_cv_have_working_vsnprintf=yes
24932-
24933-
fi
24934-
24946+
;;
24947+
esac
2493524948
fi
2493624949
if test X"$ac_cv_have_working_snprintf$ac_cv_have_working_vsnprintf" = X"yesyes"
2493724950
then :

configure.ac

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,14 +3060,15 @@ AS_IF([test X"$sudo_mktemp" = X"yes"], [
30603060
SUDO_APPEND_COMPAT_EXP(sudo_mkdtemp sudo_mkdtempat sudo_mkostempsat sudo_mkstemp sudo_mkstemps)
30613061
COMPAT_TEST_PROGS="${COMPAT_TEST_PROGS}${COMPAT_TEST_PROGS+ }mktemp_test"
30623062
])
3063-
AX_FUNC_SNPRINTF
3064-
AS_IF([test X"$ac_cv_prog_cc_c99" != X"no"], [
3063+
AS_IF([test X"$ac_cv_prog_cc_c99" != X"no" -a X"$cross_compiling" = X"yes"], [
30653064
# If we have a C99 compiler and are cross-compiling, assume
30663065
# C99-compliant v?snprintf().
3067-
AS_IF([test X"$ac_cv_have_working_snprintf$ac_cv_have_working_vsnprintf" = X"crosscross"], [
3068-
ac_cv_have_working_snprintf=yes
3069-
ac_cv_have_working_vsnprintf=yes
3070-
])
3066+
AC_CHECK_FUNCS(snprintf vsnprintf)
3067+
ac_cv_have_working_snprintf="$ac_cv_func_snprintf"
3068+
ac_cv_have_working_vsnprintf="$ac_cv_func_vsnprintf"
3069+
], [
3070+
# Check for C99-compliant v?snprintf().
3071+
AX_FUNC_SNPRINTF
30713072
])
30723073
AS_IF([test X"$ac_cv_have_working_snprintf$ac_cv_have_working_vsnprintf" = X"yesyes"], [
30733074
# System has a C99-compliant v?snprintf(), check for v?asprintf()

0 commit comments

Comments
 (0)