From df067c9ab68dd4913a1591f048d9baf4f1c8d09c Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 11 Feb 2021 06:20:31 -0500 Subject: [PATCH] Add autoconf test for localtime_r --- autofiles.sums | 4 ++-- configure | 21 +++++---------------- configure.ac | 4 +--- libqpdf/QUtil.cc | 4 ++++ libqpdf/qpdf/qpdf-config.h.in | 3 +++ 5 files changed, 15 insertions(+), 21 deletions(-) diff --git a/autofiles.sums b/autofiles.sums index 16b5c850..ce79a9a3 100644 --- a/autofiles.sums +++ b/autofiles.sums @@ -1,6 +1,6 @@ -715dae6d625977752bf7ddf7e386a2dc6ada04b8e56c6f0e7a3f7dcc9bad3209 configure.ac +cabe87703520d63bbb0ea3e069c3488fd8b43667ae29c2ee5bffffaf20321002 configure.ac d3f9ee6f6f0846888d9a10fd3dad2e4b1258be84205426cf04d7cef02d61dad7 aclocal.m4 -d12e9b7b928e7b2b9d4ffbc2af170392421376e60e40d07bdeee6a7252be8f6e libqpdf/qpdf/qpdf-config.h.in +3ed561073f0d5c9899e2120e006a7da5ec6bffb80268da1b962cd4f893b89982 libqpdf/qpdf/qpdf-config.h.in 5297971a0ef90bcd5563eb3f7127a032bb76d3ae2af7258bf13479caf8983a60 m4/ax_cxx_compile_stdcxx.m4 35bc5c645dc42d47f2daeea06f8f3e767c8a1aee6a35eb2b4854fd2ce66c3413 m4/ax_random_device.m4 1451e63710701b5f00a668f3a79b435015ef2e63547f0ad0ce8c8c062d53b599 m4/libtool.m4 diff --git a/configure b/configure index 5a043128..af6e75ff 100755 --- a/configure +++ b/configure @@ -17474,24 +17474,13 @@ $as_echo "#define HAVE_FSEEKO 1" >>confdefs.h fi -for ac_func in fseeko64 +for ac_func in fseeko64 random localtime_r do : - ac_fn_c_check_func "$LINENO" "fseeko64" "ac_cv_func_fseeko64" -if test "x$ac_cv_func_fseeko64" = xyes; then : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF -#define HAVE_FSEEKO64 1 -_ACEOF - -fi -done - - -for ac_func in random -do : - ac_fn_c_check_func "$LINENO" "random" "ac_cv_func_random" -if test "x$ac_cv_func_random" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_RANDOM 1 +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF fi diff --git a/configure.ac b/configure.ac index fd349a66..96fdef4d 100644 --- a/configure.ac +++ b/configure.ac @@ -310,9 +310,7 @@ AC_ARG_WITH(large-file-test-path, AC_SYS_LARGEFILE AC_FUNC_FSEEKO -AC_CHECK_FUNCS([fseeko64]) - -AC_CHECK_FUNCS(random) +AC_CHECK_FUNCS([fseeko64 random localtime_r]) # Check if LD supports linker scripts, and define conditional # HAVE_LD_VERSION_SCRIPT if so. This functionality is currently diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index c5dfa74c..39d21ea0 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -844,7 +844,11 @@ QUtil::get_current_qpdf_time() struct tm ltime; time_t now = time(0); tzset(); +#ifdef HAVE_LOCALTIME_R localtime_r(&now, <ime); +#else + ltime = *localtime(&now); +#endif return QPDFTime(static_cast(ltime.tm_year + 1900), static_cast(ltime.tm_mon + 1), static_cast(ltime.tm_mday), diff --git a/libqpdf/qpdf/qpdf-config.h.in b/libqpdf/qpdf/qpdf-config.h.in index bee4cc49..78ebc86d 100644 --- a/libqpdf/qpdf/qpdf-config.h.in +++ b/libqpdf/qpdf/qpdf-config.h.in @@ -21,6 +21,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H +/* Define to 1 if you have the `localtime_r' function. */ +#undef HAVE_LOCALTIME_R + /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H