Timur Davydov has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-trx/+/42199?usp=email )


Change subject: fix(threads): support GNU and POSIX strerror_r variants
......................................................................

fix(threads): support GNU and POSIX strerror_r variants

- Add required headers
- Use correct handling for GNU-specific strerror_r
- Provide fallback error string for portability

Change-Id: I642aff8a9f98823e117c4debd19384ddf5975039
---
M CommonLibs/Threads.cpp
1 file changed, 13 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/99/42199/1

diff --git a/CommonLibs/Threads.cpp b/CommonLibs/Threads.cpp
index 377a1b0..22191f0 100644
--- a/CommonLibs/Threads.cpp
+++ b/CommonLibs/Threads.cpp
@@ -27,6 +27,8 @@

 #include <string.h>
 #include <sys/types.h>
+#include <errno.h>
+#include <stdio.h>

 #include "Threads.h"
 #include "Timeval.h"
@@ -53,7 +55,17 @@
        } else {
                char buf[256];
                int err = errno;
-               char* err_str = strerror_r(err, buf, sizeof(buf));
+        char *err_str = NULL;
+#if defined(__GLIBC__) && defined(_GNU_SOURCE)
+        err_str = strerror_r(err, buf, sizeof(buf));
+#else
+        if (strerror_r(err, buf, sizeof(buf)) == 0) {
+            err_str = buf;
+        } else {
+            snprintf(buf, sizeof(buf), "Unknown error %d", err);
+            err_str = buf;
+        }
+#endif
                LOG(NOTICE) << "Thread "<< selfid << " (task " << tid << ") set 
name \"" << name << "\" failed: (" << err << ") " << err_str;
        }
 }

--
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/42199?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Change-Id: I642aff8a9f98823e117c4debd19384ddf5975039
Gerrit-Change-Number: 42199
Gerrit-PatchSet: 1
Gerrit-Owner: Timur Davydov <[email protected]>

Reply via email to