]> sigrok.org Git - libsigrokdecode.git/commitdiff
log: Use GLib printf for consistency
authorDaniel Elstner <redacted>
Sun, 13 Sep 2015 21:05:42 +0000 (23:05 +0200)
committerDaniel Elstner <redacted>
Sun, 13 Sep 2015 21:09:45 +0000 (23:09 +0200)
Just as in libsigrok, use g_vfprintf() in the log callback to make
sure we are linking to a standard-conforming printf implementation.

log.c

diff --git a/log.c b/log.c
index 73c1fdde89bca9acb797fda11500f27e913e1405..0d8bbfa5314bce0b4b7f4f35f32b4d95527b1749 100644 (file)
--- a/log.c
+++ b/log.c
@@ -23,6 +23,7 @@
 #include "libsigrokdecode.h"
 #include <stdarg.h>
 #include <stdio.h>
+#include <glib/gprintf.h>
 
 /**
  * @file
@@ -153,8 +154,6 @@ SRD_API int srd_log_callback_set_default(void)
 static int srd_logv(void *cb_data, int loglevel, const char *format,
                    va_list args)
 {
-       int ret;
-
        /* This specific log callback doesn't need the void pointer data. */
        (void)cb_data;
 
@@ -162,11 +161,12 @@ static int srd_logv(void *cb_data, int loglevel, const char *format,
        if (loglevel > cur_loglevel)
                return SRD_OK;
 
-       fputs("srd: ", stderr);
-       ret = vfprintf(stderr, format, args);
-       fprintf(stderr, "\n");
+       if (fputs("srd: ", stderr) < 0
+                       || g_vfprintf(stderr, format, args) < 0
+                       || putc('\n', stderr) < 0)
+               return SRD_ERR;
 
-       return ret;
+       return SRD_OK;
 }
 
 /** @private */