/*
- * Copyright (c) 1995-2001, Index Data.
+ * Copyright (c) 1995-2003, Index Data.
* See the file LICENSE for details.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: nmem.c,v 1.35 2002-06-12 19:42:38 adam Exp $
+ * $Id: nmem.c,v 1.40 2003-01-06 21:52:37 adam Exp $
*/
/*
#include <assert.h>
#include <string.h>
+#include <errno.h>
#include <yaz/xmalloc.h>
#include <yaz/nmem.h>
#include <yaz/log.h>
return TRUE;
}
#endif
+
+int yaz_errno(void)
+{
+ return errno;
+}
+
+void yaz_set_errno(int v)
+{
+ errno = v;
+}
+
+void yaz_strerror(char *buf, int max)
+{
+ char *cp;
+#ifdef WIN32
+ DWORD err = GetLastError();
+ if (err)
+ {
+ FormatMessage(
+ FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL,
+ err,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ (LPTSTR) buf,
+ max-1,
+ NULL);
+ }
+ else
+ *buf = '\0';
+#else
+/* UNIX */
+#if HAVE_STRERROR_R
+#if YAZ_POSIX_THREADS
+ strerror_r(errno, buf, max);
+#else
+ strcpy(buf, strerror(yaz_errno()));
+#endif
+#else
+ strcpy(buf, strerror(yaz_errno()));
+#endif
+/* UNIX */
+#endif
+ if ((cp=strrchr(buf, '\n')))
+ *cp = '\0';
+ if ((cp=strrchr(buf, '\r')))
+ *cp = '\0';
+}