apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject svn commit: r191138 - in /apr/apr/trunk: CHANGES include/apr_lib.h strings/apr_snprintf.c
Date Fri, 17 Jun 2005 12:12:36 GMT
Author: trawick
Date: Fri Jun 17 05:12:36 2005
New Revision: 191138

URL: http://svn.apache.org/viewcvs?rev=191138&view=rev
Log:
Add %pt support to apr_snprintf() for printing an apr_os_thread_t
in hex format.

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/include/apr_lib.h
    apr/apr/trunk/strings/apr_snprintf.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/CHANGES?rev=191138&r1=191137&r2=191138&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES (original)
+++ apr/apr/trunk/CHANGES Fri Jun 17 05:12:36 2005
@@ -1,5 +1,8 @@
 Changes for APR 1.2.0
 
+  *) Add %pt support to apr_snprintf() for printing an apr_os_thread_t
+     in hex format.  [Jeff Trawick]
+
    *) Support APR_SO_SNDBUF and APR_SO_RCVBUF on Windows.  PR 32177.
       [Sim <sgobbi datamanagement.it>, Jeff Trawick]
 

Modified: apr/apr/trunk/include/apr_lib.h
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/include/apr_lib.h?rev=191138&r1=191137&r2=191138&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_lib.h (original)
+++ apr/apr/trunk/include/apr_lib.h Fri Jun 17 05:12:36 2005
@@ -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

Modified: apr/apr/trunk/strings/apr_snprintf.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/strings/apr_snprintf.c?rev=191138&r1=191137&r2=191138&view=diff
==============================================================================
--- apr/apr/trunk/strings/apr_snprintf.c (original)
+++ apr/apr/trunk/strings/apr_snprintf.c Fri Jun 17 05:12:36 2005
@@ -665,6 +665,27 @@
     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
@@ -1153,6 +1174,31 @@
                     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 '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;
                     }



Mime
View raw message