]> sigrok.org Git - libsigrokdecode.git/blobdiff - log.c
install: unbreak installation with Python 3.7 (os.errno)
[libsigrokdecode.git] / log.c
diff --git a/log.c b/log.c
index f2ef818d0105a33f728ab0e25f207b951db97d4b..459a5c10be9023ad2422a4c35a015abfd79f95ee 100644 (file)
--- a/log.c
+++ b/log.c
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
 #include "libsigrokdecode-internal.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */
 #include "libsigrokdecode.h"
 #include <stdarg.h>
 #include <stdio.h>
+#include <glib/gprintf.h>
 
 /**
  * @file
@@ -152,20 +153,19 @@ 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;
 
-       /* Only output messages of at least the selected loglevel(s). */
-       if (loglevel > cur_loglevel)
-               return SRD_OK;
+       (void)loglevel;
 
-       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;
+       fflush(stderr);
+
+       return SRD_OK;
 }
 
 /** @private */
@@ -174,6 +174,10 @@ SRD_PRIV int srd_log(int loglevel, const char *format, ...)
        int ret;
        va_list args;
 
+       /* Only output messages of at least the selected loglevel(s). */
+       if (loglevel > cur_loglevel)
+               return SRD_OK;
+
        va_start(args, format);
        ret = srd_log_cb(srd_log_cb_data, loglevel, format, args);
        va_end(args);