log: Allow disabling of stdio
Some firmwares (e.g. Hostboot) don't provide stdio.h. Make sure we can
compile in these environments.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I3a5f414f12fbf9de70fb41033d610f81094848bf
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ef7506f..5b57637 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,6 +2,7 @@
add_definitions (-DMCTP_LOG_STDERR)
add_definitions (-DMCTP_HAVE_FILEIO)
+add_definitions (-DMCTP_HAVE_STDIO)
add_library (libmctp STATIC alloc.c core.c log.c libmctp.h serial.c)
diff --git a/configure.ac b/configure.ac
index 82d9737..9ae4681 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,6 +23,7 @@
# AC_ARG_WITH these in the future.
AC_DEFINE([MCTP_HAVE_SYSLOG], [1], [Define to enable syslog])
AC_DEFINE([MCTP_HAVE_FILEIO], [1], [Define to enable filesystem functions])
+AC_DEFINE([MCTP_HAVE_STDIO], [1], [Define to enable stdio functions])
AC_DEFINE([MCTP_DEFAULT_ALLOC], [1],
[Define to populate allocation functions to defaults (malloc/free)])
diff --git a/log.c b/log.c
index 4df529b..cbdbbca 100644
--- a/log.c
+++ b/log.c
@@ -1,7 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
#include <stdarg.h>
-#include <stdio.h>
#include "libmctp.h"
#include "libmctp-log.h"
@@ -10,6 +9,10 @@
#include "config.h"
#endif
+#ifdef MCTP_HAVE_STDIO
+#include <stdio.h>
+#endif
+
#ifdef MCTP_HAVE_SYSLOG
#include <syslog.h>
#endif
@@ -34,10 +37,12 @@
case MCTP_LOG_NONE:
break;
case MCTP_LOG_STDIO:
+#ifdef MCTP_HAVE_STDIO
if (level <= log_stdio_level) {
vfprintf(stderr, fmt, ap);
fputs("\n", stderr);
}
+#endif
break;
case MCTP_LOG_SYSLOG:
#ifdef MCTP_HAVE_SYSLOG