[PATCH 4/5] os: add support for %d and %i to pnprintf

Peter Hutterer peter.hutterer at who-t.net
Wed Aug 15 21:52:48 PDT 2012


The mouse driver uses %i in some debug messages

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 os/log.c              | 10 ++++++++++
 test/signal-logging.c | 21 +++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/os/log.c b/os/log.c
index 25da9f6..4348739 100644
--- a/os/log.c
+++ b/os/log.c
@@ -290,6 +290,7 @@ pnprintf(char *string, size_t size, const char *f, va_list args)
     int p_len;
     int i;
     uint64_t ui;
+    int64_t si;
 
     for (; f_idx < f_len && s_idx < size - 1; f_idx++) {
         if (f[f_idx] != '%') {
@@ -314,6 +315,15 @@ pnprintf(char *string, size_t size, const char *f, va_list args)
             for (i = 0; i < p_len && s_idx < size - 1; i++)
                 string[s_idx++] = number[i];
             break;
+        case 'i':
+        case 'd':
+            si = va_arg(args, int);
+            FormatInt64(si, number);
+            p_len = strlen_sigsafe(number);
+
+            for (i = 0; i < p_len && s_idx < size - 1; i++)
+                string[s_idx++] = number[i];
+            break;
 
         case 'p':
             string[s_idx++] = '0';
diff --git a/test/signal-logging.c b/test/signal-logging.c
index 0e352aa..3206dde 100644
--- a/test/signal-logging.c
+++ b/test/signal-logging.c
@@ -242,6 +242,27 @@ static void logging_format(void)
             ui <<= 1;
     } while(ui);
 
+    /* signed number substitution */
+    i = 0;
+    do {
+        char expected[30];
+        sprintf(expected, "(EE) %d\n", i);
+        LogMessageVerbSigSafe(X_ERROR, -1, "%d\n", i);
+        read_log_msg(logmsg);
+        assert(strcmp(logmsg, expected) == 0);
+
+
+        sprintf(expected, "(EE) %d\n", i | INT_MIN);
+        LogMessageVerbSigSafe(X_ERROR, -1, "%d\n", i | INT_MIN);
+        read_log_msg(logmsg);
+        assert(strcmp(logmsg, expected) == 0);
+
+        if (i == 0)
+            i = 1;
+        else
+            i <<= 1;
+    } while(i > INT_MIN);
+
     /* hex number substitution */
     ui = 0;
     do {
-- 
1.7.11.2



More information about the xorg-devel mailing list