X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=util%2Fnmem.c;h=8415772319d2488afaf0dfff47cd7cebfa60f7fa;hp=375957c43ffc7616e449b91c757570b59a254789;hb=4d531a1a9131d69c3b6c27fbac42837e22cff61c;hpb=b340923765c14d2ba050a171bb557474044d7e6a diff --git a/util/nmem.c b/util/nmem.c index 375957c..8415772 100644 --- a/util/nmem.c +++ b/util/nmem.c @@ -1,9 +1,9 @@ /* - * 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.34 2001-11-18 21:05:13 adam Exp $ + * $Id: nmem.c,v 1.39 2003-01-06 08:20:28 adam Exp $ */ /* @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -231,8 +232,8 @@ void *nmem_malloc(NMEM n, int size) #endif if (!n) { + yaz_log (LOG_FATAL, "calling nmem_malloc with an null pointer"); abort (); - return xmalloc(size); } #ifdef WIN32 assert (nmem_init_flag); @@ -429,3 +430,44 @@ BOOL WINAPI DllMain (HINSTANCE hinstDLL, 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 +#if HAVE_STRERROR_R + strerror_r(errno, buf, max); +#else + strcpy(buf, strerror(yaz_errno())); +#endif +#endif + if ((cp=strrchr(buf, '\n'))) + *cp = '\0'; + if ((cp=strrchr(buf, '\r'))) + *cp = '\0'; +}