Fix sample PQF
[yaz-moved-to-github.git] / util / nmem.c
index f91ecc1..24225c7 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * Copyright (c) 1995-2002, Index Data.
+ * Copyright (c) 1995-2003, Index Data.
  * See the file LICENSE for details.
  * Sebastian Hammer, Adam Dickmeiss
  *
- * $Id: nmem.c,v 1.38 2002-12-05 12:19:24 adam Exp $
+ * $Id: nmem.c,v 1.42 2003-09-16 19:46:56 adam Exp $
  */
 
 /*
@@ -452,7 +452,7 @@ void yaz_strerror(char *buf, int max)
                FORMAT_MESSAGE_FROM_SYSTEM,
                NULL,
                err,
-               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default lang */
                (LPTSTR) buf,
                max-1,
                NULL);
@@ -460,11 +460,21 @@ void yaz_strerror(char *buf, int max)
     else
        *buf = '\0';
 #else
+/* UNIX */
+#if HAVE_STRERROR_R
 #if YAZ_POSIX_THREADS
+    *buf = '\0';
     strerror_r(errno, buf, max);
+    /* if buffer is unset - use strerror anyway (GLIBC bug) */
+    if (*buf == '\0')
+        strcpy(buf, strerror(yaz_errno()));
 #else
     strcpy(buf, strerror(yaz_errno()));
 #endif
+#else
+    strcpy(buf, strerror(yaz_errno()));
+#endif
+/* UNIX */
 #endif
     if ((cp=strrchr(buf, '\n')))
        *cp = '\0';