This uses format %pt. (%pT is existing, and results in tid in
decimal.) The display will use lower-case a-f.
Comments/concerns?
I have a small itch for APR_PID_T_HEX_FMT as well.
My understanding is that this feature can go in trunk because trunk
isn't a released version yet, and it can go in 0.9.x because that is <
1.0 and not covered by the versioning guidelines (other than binary
compatibility), but 1.0 and 1.1 are feature-frozen.
Index: strings/apr_snprintf.c
===================================================================
--- strings/apr_snprintf.c (revision 190567)
+++ strings/apr_snprintf.c (working copy)
@@ -665,7 +665,28 @@
return (p);
}
+#if APR_HAS_THREADS
+static char *conv_os_thread_t_hex(apr_os_thread_t *tid, char *buf_end,
apr_size_t *len)
+{
+ union {
+ apr_os_thread_t tid;
+ apr_uint64_t alignme;
+ } u;
+ int is_negative;
+ u.tid = *tid;
+ switch(sizeof(u.tid)) {
+ case sizeof(apr_int32_t):
+ return conv_p2(*(apr_uint32_t *)&u.tid, 4, 'x', buf_end, len);
+ case sizeof(apr_int64_t):
+ return conv_p2_quad(*(apr_uint64_t *)&u.tid, 4, 'x', buf_end, len);
+ default:
+ /* not implemented; stick 0 in the buffer */
+ return conv_10(0, TRUE, &is_negative, buf_end, len);
+ }
+}
+#endif
+
/*
* Do format conversion placing the output in buffer
*/
@@ -1170,6 +1191,31 @@
#endif
break;
+ case 't':
+#if APR_HAS_THREADS
+ {
+ apr_os_thread_t *tid;
+
+ tid = va_arg(ap, apr_os_thread_t *);
+ if (tid != NULL) {
+ s = conv_os_thread_t_hex(tid, &num_buf[NUM_BUF_SIZE],
&s_len);
+ if (adjust_precision && precision < s_len)
+ s_len = precision;
+ }
+ else {
+ s = S_NULL;
+ s_len = S_NULL_LEN;
+ }
+ pad_char = ' ';
+ }
+#else
+ char_buf[0] = '0';
+ s = &char_buf[0];
+ s_len = 1;
+ pad_char = ' ';
+#endif
+ break;
+
case NUL:
/* if %p ends the string, oh well ignore it */
continue;
Index: include/apr_lib.h
===================================================================
--- include/apr_lib.h (revision 190567)
+++ include/apr_lib.h (working copy)
@@ -116,6 +116,8 @@
* [ipv6-address]:port
* %%pT takes an apr_os_thread_t * and prints it in decimal
* ('0' is printed if !APR_HAS_THREADS)
+ * %%pt takes an apr_os_thread_t * and prints it in hexadecimal
+ * ('0' is printed if !APR_HAS_THREADS)
* %%pp takes a void * and outputs it in hex
*
* The %%p hacks are to force gcc's printf warning code to skip