X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fnmem.c;h=4b6d0a4c6114f0e1d7ebd6fb06e96d84ee89c45d;hp=b3882c9157a081ff5e7bfb392252de469a425d6c;hb=4e50d9461c89fb538b1826f9cecf4475deaeed3b;hpb=2788a4851b551e1a3efb320a2878b809f2d8a9d7 diff --git a/src/nmem.c b/src/nmem.c index b3882c9..4b6d0a4 100644 --- a/src/nmem.c +++ b/src/nmem.c @@ -10,8 +10,6 @@ * This is a simple and fairly wasteful little module for nibble memory * allocation. Evemtually we'll put in something better. * - * FIXME - it also has some semaphore stuff, and stuff to handle errno. - * These should be moved to some other place! */ #if HAVE_CONFIG_H #include @@ -26,10 +24,6 @@ #include #include -#ifdef WIN32 -#include -#endif - #define NMEM_CHUNK (4*1024) struct nmem_block @@ -42,7 +36,7 @@ struct nmem_block struct nmem_control { - int total; + size_t total; struct nmem_block *blocks; struct nmem_control *next; }; @@ -115,7 +109,7 @@ void nmem_reset(NMEM n) n->total = 0; } -void *nmem_malloc(NMEM n, int size) +void *nmem_malloc(NMEM n, size_t size) { struct nmem_block *p; char *r; @@ -139,7 +133,7 @@ void *nmem_malloc(NMEM n, int size) return r; } -int nmem_total(NMEM n) +size_t nmem_total(NMEM n) { return n->total; } @@ -184,64 +178,10 @@ void nmem_transfer (NMEM dst, NMEM src) src->total = 0; } -int yaz_errno(void) -{ - return errno; -} - -void yaz_set_errno(int v) -{ - errno = v; -} - -void yaz_strerror(char *buf, int max) -{ -#ifdef WIN32 - DWORD err; -#endif - char *cp; - if (!log_level_initialized) - { - log_level = yaz_log_module_level("nmem"); - log_level_initialized = 1; - } - -#ifdef WIN32 - err = GetLastError(); - if (err) - { - FormatMessage( - FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - err, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default lang */ - (LPTSTR) buf, - max-1, - NULL); - } - else - *buf = '\0'; -#else -/* UNIX */ -#if HAVE_STRERROR_R - *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 -/* UNIX */ -#endif - if ((cp = strrchr(buf, '\n'))) - *cp = '\0'; - if ((cp = strrchr(buf, '\r'))) - *cp = '\0'; -} /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab