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/util/aos_strerror.cc b/aos/common/util/aos_strerror.cc
new file mode 100644
index 0000000..d2b2ca6
--- /dev/null
+++ b/aos/common/util/aos_strerror.cc
@@ -0,0 +1,42 @@
+#include "aos/common/util/aos_strerror.h"
+
+#include <assert.h>
+#include <sys/types.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "aos/linux_code/thread_local.h"
+
+// This code uses an overloaded function to handle the result from either
+// version of strerror_r correctly without needing a way to get the choice out
+// of the compiler/glibc/whatever explicitly.
+
+namespace {
+
+const size_t kBufferSize = 128;
+
+// Handle the result from the GNU version of strerror_r. It never fails, so
+// that's pretty easy...
+__attribute__((unused))
+char *aos_strerror_handle_result(int /*error*/, char *ret, char * /*buffer*/) {
+ return ret;
+}
+
+// Handle the result from the POSIX version of strerror_r.
+__attribute__((unused))
+char *aos_strerror_handle_result(int error, int ret, char *buffer) {
+ if (ret != 0) {
+ assert(snprintf(buffer, kBufferSize, "Unknown error %d", error) > 0);
+ }
+ return buffer;
+}
+
+} // namespace
+
+char *aos_strerror(int error) {
+ static AOS_THREAD_LOCAL char buffer[kBufferSize];
+
+ // Call the overload for whichever version we're using.
+ return aos_strerror_handle_result(
+ error, strerror_r(error, buffer, sizeof(buffer)), buffer);
+}