Changeset: cb21ff8b1379 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cb21ff8b1379
Modified Files:
        common/stream/stream.c
Branch: Oct2020
Log Message:

Use proper feature test for strerror_r and suppress warning

Distinguish xsi strerror_r and gnu strerror_r using the #if
given by the manual page (on Linux) instead of testing for
STRERROR_R_CHAR_R

Also, with the XSI strerror_r, check the return code.


diffs (44 lines):

diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -403,26 +403,27 @@ my_strerror_r(int error_nr, char *buf, s
        // 1. no strerror_r
        // 2. gnu strerror_r (returns char* and does not always fill buffer)
        // 3. xsi strerror_r (returns int and always fills the buffer)
-       char *ret;
+       char *to_move;
 #ifndef HAVE_STRERROR_R
        // Hope for the best
-       ret = strerror(error_nr);
-#else
-#ifdef STRERROR_R_CHAR_P
-       // gnu strerror_r
-       ret = strerror_r(error_nr, buf, buflen);
+       to_move = strerror(error_nr);
+#elif (_POSIX_C_SOURCE >= 200112L) && !_GNU_SOURCE
+       // standard strerror_r always writes to buf
+       int result_code = strerror_r(error_nr, buf, buflen);
+       if (result_code == 0)
+               to_move = NULL;
+       else
+               to_move = "<failed to retrieve error message>";
 #else
-       // standard strerror_r
-       (void) strerror_r(error_nr, buf, buflen);
-       ret = NULL;
+       // gnu strerror_r sometimes only returns static string, needs copy
+       to_move = strerror_r(error_nr, buf, buflen);
 #endif
-#endif
-       if (ret != NULL) {
+       if (to_move != NULL) {
                // move to buffer
-               size_t size = strlen(ret) + 1;
+               size_t size = strlen(to_move) + 1;
                assert(size <= buflen);
                // strerror_r may have return a pointer to/into the buffer
-               memmove(buf, ret, size);
+               memmove(buf, to_move, size);
                return size - 1;
        } else {
                return strlen(buf);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to