]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Define PRIuSIZE for displaying size_t
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 4 Jun 2012 10:50:34 +0000 (04:50 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 4 Jun 2012 10:50:34 +0000 (04:50 -0600)
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.

compat/types.h
configure.ac
helpers/external_acl/eDirectory_userip/ext_edirectory_userip_acl.cc

index 707a45191f62f38d056f3067ca87e75ca2840038..1d06ba6fcae96c90b0ac026dce65c01df248a3b5 100644 (file)
 #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
index 110d67bad9b2ecd2879a70afc869b102f42f7df1..8ad7d2a1869ac6d0e6d92dc79ae51ba87fc20e55 100644 (file)
@@ -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 <sys/ipc.h>
 #include <sys/msg.h>])
 
+# 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 <stdio.h>
+  ]],[[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
 
index 2c723587e411351741a7abaa29b9cddc3e8f9a5b..1777e9ff3ee15d28072b73d7260d9bb8a8ce550a 100644 (file)
@@ -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 */