got rid of all uses of strerror
This required some minor refactoring of other things and there were some
other small cleanups I noticed along the way.
diff --git a/aos/common/logging/logging.h b/aos/common/logging/logging.h
index 03f3e31..49828bf 100644
--- a/aos/common/logging/logging.h
+++ b/aos/common/logging/logging.h
@@ -7,8 +7,11 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
#include "aos/common/macros.h"
+#include "aos/common/util/aos_strerror.h"
#ifdef __cplusplus
extern "C" {
@@ -36,6 +39,7 @@
#ifdef __cplusplus
extern "C" {
#endif
+
// Actually implements the basic logging call.
// Does not check that level is valid.
void log_do(log_level level, const char *format, ...)
@@ -47,6 +51,7 @@
void log_uncork(int line, const char *function, log_level level,
const char *file, const char *format, ...)
__attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 5, 6)));
+
#ifdef __cplusplus
}
#endif
@@ -74,6 +79,17 @@
} \
} while (0)
+// Same as LOG except appends " due to %d(%s)\n" (formatted with errno and
+// aos_strerror(errno)) to the message.
+#define PLOG(level, format, args...) PELOG(level, errno, format, ##args)
+
+// Like PLOG except allows specifying an error other than errno.
+#define PELOG(level, error_in, format, args...) \
+ do { \
+ const int error = error_in; \
+ LOG(level, format " due to %d(%s)\n", ##args, error, aos_strerror(error)); \
+ } while (0);
+
// Allows format to not be a string constant.
#define LOG_DYNAMIC(level, format, args...) \
do { \
diff --git a/aos/common/logging/logging_interface.cc b/aos/common/logging/logging_interface.cc
index ae8cc01..8c45afd 100644
--- a/aos/common/logging/logging_interface.cc
+++ b/aos/common/logging/logging_interface.cc
@@ -30,8 +30,8 @@
const int ret = vsnprintf(output, size, format, ap);
typedef ::std::common_type<typeof(ret), typeof(size)>::type RetType;
if (ret < 0) {
- LOG(FATAL, "vsnprintf(%p, %zd, %s, args) failed with %d (%s)\n",
- output, size, format, errno, strerror(errno));
+ PLOG(FATAL, "vsnprintf(%p, %zd, %s, args) failed",
+ output, size, format);
} else if (static_cast<RetType>(ret) >= static_cast<RetType>(size)) {
// Overwrite the '\0' at the end of the existing data and
// copy in the one on the end of continued.