Changeset: 336b3853b610 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/336b3853b610
Modified Files:
        cmake/monetdb-defines.cmake
        gdk/gdk_posix.c
        gdk/gdk_posix.h
Branch: Aug2024
Log Message:

Totally forget about a strerror_r() function which returns char *.
strerror_r() returning char * was the old GNU definition, but in POSIX
the function returns int.
Also, if strerror_s is available, use it.


diffs (46 lines):

diff --git a/cmake/monetdb-defines.cmake b/cmake/monetdb-defines.cmake
--- a/cmake/monetdb-defines.cmake
+++ b/cmake/monetdb-defines.cmake
@@ -84,6 +84,7 @@ function(monetdb_configure_defines)
   check_function_exists("getuid" HAVE_GETUID)
   check_symbol_exists("gmtime_r" "time.h" HAVE_GMTIME_R)
   check_symbol_exists("localtime_r" "time.h" HAVE_LOCALTIME_R)
+  check_symbol_exists("strerror_s" "string.h" HAVE_STRERROR_S)
   check_symbol_exists("strerror_r" "string.h" HAVE_STRERROR_R)
   check_function_exists("lockf" HAVE_LOCKF)
   check_symbol_exists("madvise" "sys/mman.h" HAVE_MADVISE)
diff --git a/gdk/gdk_posix.c b/gdk/gdk_posix.c
--- a/gdk/gdk_posix.c
+++ b/gdk/gdk_posix.c
@@ -1013,7 +1013,7 @@ ctime_r(const time_t *restrict t, char *
 }
 #endif
 
-#ifndef HAVE_STRERROR_R
+#if !defined(HAVE_STRERROR_R) && !defined(HAVE_STRERROR_S)
 static MT_Lock strerrlock = MT_LOCK_INITIALIZER(strerrlock);
 
 int
diff --git a/gdk/gdk_posix.h b/gdk/gdk_posix.h
--- a/gdk/gdk_posix.h
+++ b/gdk/gdk_posix.h
@@ -182,14 +182,15 @@ gdk_export int strerror_r(int errnum, ch
 static inline const char *
 GDKstrerror(int errnum, char *buf, size_t buflen)
 {
-#if !defined(_GNU_SOURCE) || ((_POSIX_C_SOURCE >= 200112L) && !_GNU_SOURCE)
+#ifdef HAVE_STRERROR_S
+       if (strerror_s(buf, buflen, errnum) == 0)
+               return buf;
+#else
        if (strerror_r(errnum, buf, buflen) == 0)
                return buf;
+#endif
        snprintf(buf, buflen, "Unknown error %d", errnum);
        return buf;
-#else
-       return strerror_r(errnum, buf, buflen);
-#endif
 }
 
 #endif /* GDK_POSIX_H */
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to