trawick 2003/04/17 10:31:56
Modified: . CHANGES
include apr_lib.h
strings apr_snprintf.c
Log:
Add %pT support to apr_snprintf() for printing an apr_os_thread_t.
(from a series of suggestions on #apr)
Revision Changes Path
1.401 +3 -0 apr/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/apr/CHANGES,v
retrieving revision 1.400
retrieving revision 1.401
diff -u -r1.400 -r1.401
--- CHANGES 15 Apr 2003 22:28:13 -0000 1.400
+++ CHANGES 17 Apr 2003 17:31:54 -0000 1.401
@@ -1,5 +1,8 @@
Changes with APR 0.9.4
+ *) Add %pT support to apr_snprintf() for printing an apr_os_thread_t.
+ [Jeff Trawick]
+
*) Add APR_TCP_NODELAY_INHERITED & APR_O_NONBLOCK_INHERITED to apr.hw
[Allan Edwards]
1.63 +2 -0 apr/include/apr_lib.h
Index: apr_lib.h
===================================================================
RCS file: /home/cvs/apr/include/apr_lib.h,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -r1.62 -r1.63
--- apr_lib.h 5 Mar 2003 21:22:26 -0000 1.62
+++ apr_lib.h 17 Apr 2003 17:31:55 -0000 1.63
@@ -155,6 +155,8 @@
* %%pA takes a struct in_addr *, and prints it as a.b.c.d
* %%pI takes an apr_sockaddr_t * and prints it as a.b.c.d:port or
* [ipv6-address]:port
+ * %%pT takes an apr_os_thread_t * and prints it in decimal
+ * ('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
1.34 +50 -0 apr/strings/apr_snprintf.c
Index: apr_snprintf.c
===================================================================
RCS file: /home/cvs/apr/strings/apr_snprintf.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- apr_snprintf.c 1 Jan 2003 00:01:55 -0000 1.33
+++ apr_snprintf.c 17 Apr 2003 17:31:56 -0000 1.34
@@ -62,6 +62,7 @@
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_network_io.h"
+#include "apr_portable.h"
#include <math.h>
#if APR_HAVE_CTYPE_H
#include <ctype.h>
@@ -534,6 +535,30 @@
+#if APR_HAS_THREADS
+static char *conv_os_thread_t(apr_os_thread_t *tid, char *buf_end, int *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_10(*(apr_uint32_t *)&u.tid, TRUE, &is_negative, buf_end,
len);
+ case sizeof(apr_int64_t):
+ return conv_10_quad(*(apr_uint64_t *)&u.tid, TRUE, &is_negative,
buf_end, len);
+ default:
+ /* not implemented; stick 0 in the buffer */
+ return conv_10(0, TRUE, &is_negative, buf_end, len);
+ }
+}
+#endif
+
+
+
/*
* Convert a floating point number to a string formats 'f', 'e' or 'E'.
* The result is placed in buf, and len denotes the length of the string
@@ -1159,6 +1184,31 @@
pad_char = ' ';
}
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(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 */