summaryrefslogtreecommitdiff
path: root/configure.ac
diff options
context:
space:
mode:
authorJaehyun Kim <jeik01.kim@samsung.com>2024-06-07 18:11:13 +0900
committerJaehyun Kim <jeik01.kim@samsung.com>2024-06-07 18:12:26 +0900
commitef7e2e6361b2deb5ef8c0a62e1b88f3263798a2c (patch)
tree4391a851ecd85deaa7b11a866a28519dafd3cde8 /configure.ac
parent9dff09857ab05c287e95170ce39f7605ea1a42c0 (diff)
downloadtcpdump-tizen.tar.gz
tcpdump-tizen.tar.bz2
tcpdump-tizen.zip
Change-Id: I9dca705f49f9c4a993bccc3911db6f527cd99c8e Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
Diffstat (limited to 'configure.ac')
-rw-r--r--configure.ac123
1 files changed, 67 insertions, 56 deletions
diff --git a/configure.ac b/configure.ac
index 56e2a62..e077285 100644
--- a/configure.ac
+++ b/configure.ac
@@ -783,63 +783,74 @@ AC_CHECK_TYPE([u_int64_t], ,
])
#
-# Check for <inttypes.h>
-#
-AC_CHECK_HEADERS(inttypes.h,
- [
- #
- # OK, we have inttypes.h, but does it define all the PRI[doxu]64 macros?
- # Some systems have an inttypes.h that doesn't define all of them.
- #
- AC_MSG_CHECKING([[whether inttypes.h defines the PRI[doxu]64 macros]])
- AC_COMPILE_IFELSE(
- [
- AC_LANG_SOURCE(
- [[
- #include <inttypes.h>
- #include <stdio.h>
- #include <sys/types.h>
-
- main()
- {
- printf("%" PRId64 "\n", (uint64_t)1);
- printf("%" PRIo64 "\n", (uint64_t)1);
- printf("%" PRIx64 "\n", (uint64_t)1);
- printf("%" PRIu64 "\n", (uint64_t)1);
- }
- ]])
- ],
- [
- AC_MSG_RESULT(yes)
- ac_lbl_inttypes_h_defines_formats=yes
- ],
- [
- AC_MSG_RESULT(no)
- ac_lbl_inttypes_h_defines_formats=no
- ])
- ],
- [
- #
- # We don't have inttypes.h, so it obviously can't define those
- # macros.
- #
- ac_lbl_inttypes_h_defines_formats=no
- ])
-if test "$ac_lbl_inttypes_h_defines_formats" = no; then
- AC_LBL_CHECK_64BIT_FORMAT(l,
+# It became apparent at some point that using a suitable C99 compiler does not
+# automatically mean snprintf(3) implementation in the libc supports all the
+# modifiers and specifiers used in the project, so let's test that before the
+# build, not after.
+#
+# Testing the sizeof_t length modifier takes making an snprintf() call and
+# comparing the actual result with the expected result. If this fails, it will
+# most likely happen at run time, not compile time.
+#
+# Testing the 64-bit conversion specifiers in addition to that requires the
+# <inttypes.h> header to be present and the macros to be defined, so if this
+# fails, it will more likely happen at compile time.
+#
+AC_MSG_CHECKING([whether snprintf is suitable])
+AC_RUN_IFELSE(
[
- AC_LBL_CHECK_64BIT_FORMAT(ll,
- [
- AC_LBL_CHECK_64BIT_FORMAT(L,
- [
- AC_LBL_CHECK_64BIT_FORMAT(q,
- [
- AC_MSG_ERROR([neither %llx nor %Lx nor %qx worked on a 64-bit integer])
- ])
- ])
- ])
- ])
-fi
+ AC_LANG_SOURCE([[
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+#include <sys/types.h>
+
+int main()
+{
+ char buf[100];
+ uint64_t t = (uint64_t)1 << 32;
+
+ snprintf(buf, sizeof(buf), "%zu", sizeof(buf));
+ if (strncmp(buf, "100", sizeof(buf)))
+ return 1;
+
+ snprintf(buf, sizeof(buf), "%zd", -sizeof(buf));
+ if (strncmp(buf, "-100", sizeof(buf)))
+ return 2;
+
+ snprintf(buf, sizeof(buf), "%" PRId64, -t);
+ if (strncmp(buf, "-4294967296", sizeof(buf)))
+ return 3;
+
+ snprintf(buf, sizeof(buf), "0o%" PRIo64, t);
+ if (strncmp(buf, "0o40000000000", sizeof(buf)))
+ return 4;
+
+ snprintf(buf, sizeof(buf), "0x%" PRIx64, t);
+ if (strncmp(buf, "0x100000000", sizeof(buf)))
+ return 5;
+
+ snprintf(buf, sizeof(buf), "%" PRIu64, t);
+ if (strncmp(buf, "4294967296", sizeof(buf)))
+ return 6;
+
+ return 0;
+}
+ ]])
+ ],
+ [
+ AC_MSG_RESULT(yes)
+ ],
+ [
+ AC_MSG_RESULT(no)
+ AC_MSG_ERROR(
+[The snprintf(3) implementation in this libc is not suitable,
+tcpdump would not work correctly even if it managed to compile.])
+ ],
+ [
+ AC_MSG_RESULT(not while cross-compiling)
+ ]
+)
#
# Check for some headers introduced in later versions of libpcap