Hopefully there isn't a reason why this can't be implemented portably. Speak up quickly if you know of one :)

Apache needs to format a 64-bit quantity in hex in a few places. Since hex formatting is typically supported for unsigned values only, the best compromise seems to be to have a format string for APR_UINT64_T and cast the argument to apr_uint64_t (if it is known to be safe in that context, of course).

An unfortunately ugly example:

  apr_time_t now;

  apr_snprintf(..., "microsecs in hex: %" APR_UINT64_T_HEX_FMT,
               (apr_uint64_t))


APR_TIME_T_HEX_FMT wouldn't be pretty since apr_time_t is signed but hex formats take unsigned arguments. At least APR_UINT64_T_HEX_FMT is good clean fun by itself.
Index: configure.in
===================================================================
RCS file: /home/cvs/apr/configure.in,v
retrieving revision 1.524
diff -u -r1.524 configure.in
--- configure.in        4 Apr 2003 04:15:59 -0000       1.524
+++ configure.in        15 Apr 2003 17:42:36 -0000
@@ -1079,6 +1079,8 @@
     int64_t_fmt_len='#define APR_INT64_T_FMT_LEN 1'
     uint64_t_fmt='#define APR_UINT64_T_FMT "u"'
     uint64_t_fmt_len='#define APR_UINT64_T_FMT_LEN 1'
+    uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "x"'
+    uint64_t_hex_fmt_len='#define APR_UINT64_T_HEX_FMT_LEN 1'
     int64_value="int"
     long_value=int
     int64_strfn="strtoi"
@@ -1088,6 +1090,8 @@
     int64_t_fmt_len='#define APR_INT64_T_FMT_LEN 2'
     uint64_t_fmt='#define APR_UINT64_T_FMT "lu"'
     uint64_t_fmt_len='#define APR_UINT64_T_FMT_LEN 2'
+    uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "lx"'
+    uint64_t_hex_fmt_len='#define APR_UINT64_T_HEX_FMT_LEN 2'
     int64_value="long"
     long_value=long
     int64_strfn="strtol"
@@ -1101,6 +1105,8 @@
     int64_t_fmt_len='#define APR_INT64_T_FMT_LEN 3'
     uint64_t_fmt='#define APR_UINT64_T_FMT "llu"'
     uint64_t_fmt_len='#define APR_UINT64_T_FMT_LEN 3'
+    uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "llx"'
+    uint64_t_hex_fmt_len='#define APR_UINT64_T_HEX_FMT_LEN 3'
     int64_value="long long"
     long_value="long long"
     int64_strfn="strtoll"
@@ -1110,6 +1116,8 @@
     int64_t_fmt_len='#define APR_INT64_T_FMT_LEN 2'
     uint64_t_fmt='#define APR_UINT64_T_FMT "Lu"'
     uint64_t_fmt_len='#define APR_UINT64_T_FMT_LEN 2'
+    uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "Lx"'
+    uint64_t_hex_fmt_len='#define APR_UINT64_T_HEX_FMT_LEN 2'
     int64_value="long double"
     long_value="long double"
     int64_strfn="strtoll"
@@ -1119,6 +1127,8 @@
     int64_t_fmt_len='#define APR_INT64_T_FMT_LEN 2'
     uint64_t_fmt='#define APR_UINT64_T_FMT "qu"'
     uint64_t_fmt_len='#define APR_UINT64_T_FMT_LEN 2'
+    uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "qx"'
+    uint64_t_hex_fmt_len='#define APR_UINT64_T_HEX_FMT_LEN 2'
     int64_value="__int64"
     long_value="__int64"
     int64_strfn="strtoll"
@@ -1130,6 +1140,8 @@
     int64_t_fmt_len='#error Can not determine the proper size for apr_int64_t'
     uint64_t_fmt='#error Can not determine the proper size for apr_int64_t'
     uint64_t_fmt_len='#error Can not determine the proper size for apr_int64_t'
+    uint64_t_hex_fmt='#error Can not determine the proper size for 
apr_uint64_t'
+    uint64_t_hex_fmt_len='#define Can not determine the proper size for 
apr_uint64_t'
 fi
 
 # If present, allow the C99 macro INT64_C to override our conversion.
@@ -1270,6 +1282,8 @@
 AC_SUBST(int64_t_fmt_len) 
 AC_SUBST(uint64_t_fmt) 
 AC_SUBST(uint64_t_fmt_len) 
+AC_SUBST(uint64_t_hex_fmt) 
+AC_SUBST(uint64_t_hex_fmt_len) 
 AC_SUBST(ssize_t_fmt) 
 AC_SUBST(size_t_fmt)
 AC_SUBST(off_t_fmt) 
Index: include/apr.h.in
===================================================================
RCS file: /home/cvs/apr/include/apr.h.in,v
retrieving revision 1.122
diff -u -r1.122 apr.h.in
--- include/apr.h.in    23 Mar 2003 02:25:02 -0000      1.122
+++ include/apr.h.in    15 Apr 2003 17:42:36 -0000
@@ -396,6 +396,10 @@
 @uint64_t_fmt@
 @uint64_t_fmt_len@
 
+/* And APR_UINT64_T_HEX_FMT */
[EMAIL PROTECTED]@
[EMAIL PROTECTED]@
+
 /* Deal with atoi64 variables ... these should move to apr_private.h */
 #define APR_HAVE_INT64_STRFN  @have_int64_strfn@
 #define APR_INT64_STRFN              @int64_strfn@
Index: include/apr.hnw
===================================================================
RCS file: /home/cvs/apr/include/apr.hnw,v
retrieving revision 1.33
diff -u -r1.33 apr.hnw
--- include/apr.hnw     23 Mar 2003 02:25:02 -0000      1.33
+++ include/apr.hnw     15 Apr 2003 17:42:36 -0000
@@ -362,6 +362,8 @@
 #define APR_INT64_T_FMT_LEN      3
 #define APR_UINT64_T_FMT         "llu"
 #define APR_UINT64_T_FMT_LEN     3
+#define APR_UINT64_T_HEX_FMT     "llx"
+#define APR_UINT64_T_HEX_FMT_LEN 3
 #define APR_TIME_T_FMT APR_INT64_T_FMT
 
 /* Deal with atoi64 variables ... these should move to apr_private.h */
Index: include/apr.hw
===================================================================
RCS file: /home/cvs/apr/include/apr.hw,v
retrieving revision 1.113
diff -u -r1.113 apr.hw
--- include/apr.hw      23 Mar 2003 02:25:02 -0000      1.113
+++ include/apr.hw      15 Apr 2003 17:42:37 -0000
@@ -495,6 +495,8 @@
 #define APR_INT64_T_FMT_LEN      4
 #define APR_UINT64_T_FMT         "I64u"
 #define APR_UINT64_T_FMT_LEN     4
+#define APR_UINT64_T_HEX_FMT     "I64x"
+#define APR_UINT64_T_HEX_FMT_LEN 4
 
 /* Deal with atoi64 variables ... these should move to apr_private.h */
 /* MSVC 7.0 introduced _strtoui64 */
 

Reply via email to