From 602a98c8b988496122fc731e0be40a36ed02f6c8 Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Mon, 22 Aug 2016 18:23:45 -0300 Subject: [PATCH] eina_error: provide a fallback when strerror_r() is not available. --- src/lib/eina/eina_error.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lib/eina/eina_error.c b/src/lib/eina/eina_error.c index 3e09f070cd..08c3c83537 100644 --- a/src/lib/eina/eina_error.c +++ b/src/lib/eina/eina_error.c @@ -38,6 +38,7 @@ #include "eina_error.h" #include "eina_stringshare.h" #include "eina_lock.h" +#include "eina_str.h" #ifdef EINA_HAVE_THREADS #include "eina_hash.h" #endif @@ -321,6 +322,16 @@ eina_error_msg_get(Eina_Error error) # else /* STRERROR_R_CHAR_P */ str = strerror_r(error, buf, sizeof(buf)); /* GNU */ # endif /* ! STRERROR_R_CHAR_P */ +#else + /* not so good fallback. Usually strerror(err) will + * return a const string if a known error (what we use), + * and will return a pointer to a global modified string + * formatted with "Unknown error XXXX".. which we just + * ignore... so while it's not super-correct, this + * should work well. + */ + eina_strlcpy(buf, strerror(error), sizeof(buf)); + str = buf; #endif /* HAVE_STRERROR_R */ if (!str)