From 79b486cea07c6352407a289d3b4b9a8545b470e6 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 5 Dec 2002 12:19:23 +0000 Subject: [PATCH] New function yaz_strerror. --- CHANGELOG | 3 +++ client/client.c | 8 ++++++-- include/yaz/nmem.h | 45 +++------------------------------------------ util/log.c | 23 ++++------------------- util/nmem.c | 33 ++++++++++++++++++++++++++++++++- 5 files changed, 48 insertions(+), 64 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index daadce0..a8647a7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ Possible compatibility problems with earlier versions marked with '*'. +New function yaz_strerror which is a portable wrapper for +strerror/strerror_r/GetLastMessage. + ZOOM_record_get supports type "xml" in which case OAI MARC is returned for MARC. If type is "MarcXML" , MARC XML is returned. diff --git a/client/client.c b/client/client.c index b7b7e12..4e77d74 100644 --- a/client/client.c +++ b/client/client.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: client.c,v 1.174 2002-11-08 12:23:38 adam Exp $ + * $Id: client.c,v 1.175 2002-12-05 12:19:23 adam Exp $ */ #include @@ -472,7 +472,11 @@ int cmd_open(char *arg) { printf ("error = %s\n", cs_strerror(conn)); if (conn->cerrno == CSYSERR) - perror("system"); + { + char msg[256]; + yaz_strerror(msg, sizeof(msg)); + printf ("%s\n", msg); + } cs_close(conn); conn = 0; return 0; diff --git a/include/yaz/nmem.h b/include/yaz/nmem.h index 0f5bf4c..1a0a260 100644 --- a/include/yaz/nmem.h +++ b/include/yaz/nmem.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995-2001, Index Data. + * Copyright (c) 1995-2002, Index Data. * * Permission to use, copy, modify, distribute, and sell this software and * its documentation, in whole or in part, for any purpose, is hereby granted, @@ -23,47 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Log: nmem.h,v $ - * Revision 1.8 2002-09-25 12:37:07 adam - * Thread-safe handling of errno variable. - * For server option -a@ produces APDU prints in YAZ log. - * - * Revision 1.7 2002/09/10 18:41:18 adam - * Added yaz_errno - * - * Revision 1.6 2001/06/26 14:11:27 adam - * Added MUTEX functions for NMEM module (used by OID utility). - * - * Revision 1.5 2001/03/25 21:55:12 adam - * Added odr_intdup. Ztest server returns TaskPackage for ItemUpdate. - * - * Revision 1.4 2000/05/09 11:48:58 adam - * Fix (bug introduced by previous commit). - * - * Revision 1.3 2000/05/09 10:55:05 adam - * Public nmem_print_list (for debugging). - * - * Revision 1.2 2000/02/28 11:20:06 adam - * Using autoconf. New definitions: YAZ_BEGIN_CDECL/YAZ_END_CDECL. - * - * Revision 1.1 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.10 1998/10/19 15:24:20 adam - * New nmem utility, nmem_transfer, that transfer blocks from one - * NMEM to another. - * - * Revision 1.9 1998/10/13 16:00:17 adam - * Implemented nmem_critical_{enter,leave}. - * - * Revision 1.8 1998/07/20 12:35:59 adam - * Added more memory diagnostics (when NMEM_DEBUG is 1). - * - * Revision 1.7 1997/10/31 12:20:08 adam - * Improved memory debugging for xmalloc/nmem.c. References to NMEM - * instead of ODR in n ESPEC-1 handling in source d1_espec.c. - * Bug fix: missing fclose in data1_read_espec1. - * + * $Id: nmem.h,v 1.9 2002-12-05 12:19:23 adam Exp $ */ #ifndef NMEM_H @@ -135,6 +95,7 @@ YAZ_EXPORT void nmem_init (void); YAZ_EXPORT void nmem_exit (void); YAZ_EXPORT int yaz_errno (void); YAZ_EXPORT void yaz_set_errno (int v); +YAZ_EXPORT void yaz_strerror(char *buf, int max); YAZ_END_CDECL diff --git a/util/log.c b/util/log.c index 5520419..5fa4d5e 100644 --- a/util/log.c +++ b/util/log.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: log.c,v 1.31 2002-11-26 16:56:39 adam Exp $ + * $Id: log.c,v 1.32 2002-12-05 12:19:24 adam Exp $ */ #if HAVE_CONFIG_H @@ -162,24 +162,9 @@ void yaz_log(int level, const char *fmt, ...) /* WIN32 */ if (o_level & LOG_ERRNO) { -#ifdef WIN32 - DWORD err = GetLastError(); - if (err) - { - strcat(buf, " ["); - FormatMessage( - FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - err, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) buf + strlen(buf), - 2048, - NULL); - strcat(buf, "]"); - } -#else - sprintf(buf + strlen(buf), " [%s]", strerror(yaz_errno())); -#endif + strcat(buf, " ["); + yaz_strerror(buf+strlen(buf), 2048); + strcat(buf, "]"); } va_end (ap); if (start_hook_func) diff --git a/util/nmem.c b/util/nmem.c index 75cbd20..f91ecc1 100644 --- a/util/nmem.c +++ b/util/nmem.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: nmem.c,v 1.37 2002-09-25 12:37:07 adam Exp $ + * $Id: nmem.c,v 1.38 2002-12-05 12:19:24 adam Exp $ */ /* @@ -440,3 +440,34 @@ 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 YAZ_POSIX_THREADS + 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'; +} -- 1.7.10.4