summaryrefslogtreecommitdiff
path: root/strings
diff options
context:
space:
mode:
authortrawick <trawick@13f79535-47bb-0310-9956-ffa450edef68>2003-04-17 17:31:56 +0000
committertrawick <trawick@13f79535-47bb-0310-9956-ffa450edef68>2003-04-17 17:31:56 +0000
commit154461f9b6e1b9b8bbff5deb5ae7cd11dc7ae23a (patch)
tree03bc172edff28602ffe7176dfce09dce907e7a91 /strings
parent7445ed27c8ee162becfe5a37e84255a450ed93f2 (diff)
downloadlibapr-154461f9b6e1b9b8bbff5deb5ae7cd11dc7ae23a.tar.gz
Add %pT support to apr_snprintf() for printing an apr_os_thread_t.
(from a series of suggestions on #apr) git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64485 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'strings')
-rw-r--r--strings/apr_snprintf.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/strings/apr_snprintf.c b/strings/apr_snprintf.c
index 191503c3c..dbf8a473a 100644
--- a/strings/apr_snprintf.c
+++ b/strings/apr_snprintf.c
@@ -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 @@ static char *conv_apr_sockaddr(apr_sockaddr_t *sa, char *buf_end, int *len)
+#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
@@ -1160,6 +1185,31 @@ APR_DECLARE(int) apr_vformatter(int (*flush_func)(apr_vformatter_buff_t *),
}
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 */
continue;