From: Amos Jeffries Date: Mon, 4 Jun 2012 10:50:34 +0000 (-0600) Subject: Define PRIuSIZE for displaying size_t X-Git-Tag: SQUID_3_2_0_18~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76f00ba4c9df84ec0e56565b279131218481df6d;p=thirdparty%2Fsquid.git Define PRIuSIZE for displaying size_t This allows us to avoid casting size_t to long long for printf. ./configure script auto-detects the supposedly standard %zu macro in case it is missing and compat/types.h defines some alternatives for systems which do not define it. --- diff --git a/compat/types.h b/compat/types.h index 707a45191f..1d06ba6fca 100644 --- a/compat/types.h +++ b/compat/types.h @@ -122,6 +122,21 @@ #endif #endif +#ifndef PRIuSIZE +// NP: configure checks for support of %zu and defines where possible +#if SIZEOF_SIZE_T == 4 && _SQUID_MINGW_ +#define PRIuSIZE "I32u" +#elif SIZEOF_SIZE_T == 4 +#define PRIuSIZE "u" +#elif SIZEOF_SIZE_T == 8 && _SQUID_MINGW_ +#define PRIuSIZE "I64u" +#elif SIZEOF_SIZE_T == 8 +#define PRIuSIZE "lu" +#else +#error size_t is not 32-bit or 64-bit +#endif +#endif /* PRIuSIZE */ + #ifndef HAVE_MODE_T typedef unsigned short mode_t; #endif diff --git a/configure.ac b/configure.ac index 110d67bad9..8ad7d2a186 100644 --- a/configure.ac +++ b/configure.ac @@ -2501,6 +2501,8 @@ AC_CHECK_TYPE([bool]) #need the defines for PRId64 AC_CHECK_SIZEOF(int64_t) AC_CHECK_SIZEOF(long) +#need the defines for PRIuSIZE +AC_CHECK_SIZEOF(size_t) #need the define for overflow checks AC_CHECK_SIZEOF(off_t) AC_CHECK_SIZEOF(size_t) @@ -2532,6 +2534,17 @@ AC_CHECK_TYPE(mtyp_t,AC_DEFINE(HAVE_MTYP_T,1, #include #include ]) +# check for compiler support of %zu printf macro +AH_TEMPLATE(PRIuSIZE,[Compiler supports %zu printf macro]) +AC_MSG_CHECKING([for compiler %zu support]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include + ]],[[size_t n=1;printf("%zu",n);]])],[ + AC_DEFINE(PRIuSIZE,"zu") + AC_MSG_RESULT(yes) + ],[AC_MSG_RESULT(no)],[AC_MSG_RESULT(no)]) + + dnl Check for special functions AC_FUNC_ALLOCA diff --git a/helpers/external_acl/eDirectory_userip/ext_edirectory_userip_acl.cc b/helpers/external_acl/eDirectory_userip/ext_edirectory_userip_acl.cc index 2c723587e4..1777e9ff3e 100644 --- a/helpers/external_acl/eDirectory_userip/ext_edirectory_userip_acl.cc +++ b/helpers/external_acl/eDirectory_userip/ext_edirectory_userip_acl.cc @@ -242,7 +242,7 @@ local_printfx(const char *msg,...) *(dbuf) = '\0'; } else { /* FAIL */ - debug("local_printfx() FAILURE: %zd\n", x); + debug("local_printfx() FAILURE: %" PRIuSIZE "\n", x); } /* stdout needs to be flushed for it to work with Squid */ @@ -475,7 +475,7 @@ DisplayConf() DisplayVersion(); local_printfx("\n"); local_printfx("Configuration:\n"); - local_printfx(" EDUI_MAXLEN: %zd\n", EDUI_MAXLEN); + local_printfx(" EDUI_MAXLEN: %u\n", EDUI_MAXLEN); if (edui_conf.mode & EDUI_MODE_DEBUG) local_printfx(" Debug mode: ON\n"); else @@ -1261,7 +1261,7 @@ SearchIPLDAP(edui_ldap_t *l) memcpy(bufa, l->val[i]->bv_val, j); z = BinarySplit(bufa, j, '#', bufb, sizeof(bufb)); /* BINARY DEBUGGING * - local_printfx("value[%zd]: BinarySplit(", (size_t) i); + local_printfx("value[%" PRIuSIZE "]: BinarySplit(", (size_t) i); for (k = 0; k < z; k++) { c = (int) bufb[k]; if (c < 0) @@ -1275,7 +1275,7 @@ SearchIPLDAP(edui_ldap_t *l) c = c + 256; local_printfx("%02X", c); } - local_printfx("): %zd\n", (size_t) z); + local_printfx("): %" PRIuSIZE "\n", (size_t) z); * BINARY DEBUGGING */ z = j - z - 1; j = atoi(bufb); @@ -1759,7 +1759,7 @@ MainSafe(int argc, char **argv) edui_elap = 0; k = strlen(bufa); /* BINARY DEBUGGING * - local_printfx("while() -> bufa[%zd]: %s", k, bufa); + local_printfx("while() -> bufa[%" PRIuSIZE "]: %s", k, bufa); for (i = 0; i < k; i++) local_printfx("%02X", bufa[i]); local_printfx("\n"); @@ -1866,10 +1866,10 @@ MainSafe(int argc, char **argv) /* If we got a group string, split it */ if (p != NULL) { /* Split string */ - debug("StringSplit(%s, ' ', %s, %zd)\n", bufa, bufb, sizeof(bufb)); + debug("StringSplit(%s, ' ', %s, %" PRIuSIZE ")\n", bufa, bufb, sizeof(bufb)); i = StringSplit(bufa, ' ', bufb, sizeof(bufb)); if (i > 0) { - debug("StringSplit(%s, %s) done. Result: %zd\n", bufa, bufb, i); + debug("StringSplit(%s, %s) done. Result: %" PRIuSIZE "\n", bufa, bufb, i); /* Got a group to match against */ x = ConvertIP(&edui_ldap, bufb); if (x < 0) { @@ -1907,8 +1907,8 @@ MainSafe(int argc, char **argv) } } } else { - debug("StringSplit() -> Error: %zu\n", i); - local_printfx("ERR (StringSplit Error %d)\n", i); + debug("StringSplit() -> Error: %" PRIuSIZE "\n", i); + local_printfx("ERR (StringSplit Error %" PRIuSIZE ")\n", i); } } else { /* No group to match against, only an IP */