From 021f5586a328c6600460aa9f9be664ba19ba20d4 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 23 Feb 2007 10:15:00 +0000 Subject: [PATCH] Added snprintf/vsnprintf wrappers for systems that don't have limits (heavens forbid). --- NEWS | 3 +++ include/yaz/Makefile.am | 4 ++-- include/yaz/snprintf.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++ src/Makefile.am | 4 ++-- src/libxml2_error.c | 9 +++----- src/log.c | 16 ++++--------- src/marcdisp.c | 17 ++++---------- src/odr.c | 13 +++-------- src/snprintf.c | 44 ++++++++++++++++++++++++++++++++++++ src/wrbuf.c | 14 +++--------- win/makefile | 3 ++- 11 files changed, 127 insertions(+), 57 deletions(-) create mode 100644 include/yaz/snprintf.h create mode 100644 src/snprintf.c diff --git a/NEWS b/NEWS index 7611285..9cc18b5 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +Added snprintf/vsnprintf wrappers for systems that don't have +limits (heavens forbid). + Fixed bug in ZOOM-C's event and task handling. If a ZOOM task was created before all previous tasks were completed and removed from the task queue, the new task could be removed by a mistake. diff --git a/include/yaz/Makefile.am b/include/yaz/Makefile.am index 9f9dbd2..7a75208 100644 --- a/include/yaz/Makefile.am +++ b/include/yaz/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.38 2007-01-08 10:48:07 adam Exp $ +## $Id: Makefile.am,v 1.39 2007-02-23 10:15:01 adam Exp $ pkginclude_HEADERS= backend.h ccl.h ccl_xml.h cql.h comstack.h \ diagbib1.h diagsrw.h diagsru_update.h sortspec.h log.h logrpn.h marcdisp.h \ @@ -7,7 +7,7 @@ pkginclude_HEADERS= backend.h ccl.h ccl_xml.h cql.h comstack.h \ readconf.h record_conv.h retrieval.h statserv.h \ tcpip.h test.h timing.h unix.h tpath.h wrbuf.h xmalloc.h \ yaz-ccl.h yaz-iconv.h yaz-util.h yaz-version.h yconfig.h proto.h \ - xmlquery.h libxml2_error.h xmltypes.h \ + xmlquery.h libxml2_error.h xmltypes.h snprintf.h \ \ ill.h ill-core.h item-req.h z-accdes1.h z-accform1.h \ z-acckrb1.h z-core.h z-date.h z-diag1.h z-espec1.h z-estask.h z-exp.h \ diff --git a/include/yaz/snprintf.h b/include/yaz/snprintf.h new file mode 100644 index 0000000..ee93e6c --- /dev/null +++ b/include/yaz/snprintf.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 1995-2007, Index Data + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Index Data nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* $Id: snprintf.h,v 1.1 2007-02-23 10:15:01 adam Exp $ */ + +/** + * \file snprintf.h + * \brief Header for config file reading utilities + */ + +#ifndef YAZ_SNPRINTF_H +#define YAZ_SNPRINTF_H + +#include +#include +#include + +YAZ_BEGIN_CDECL + +YAZ_EXPORT void yaz_snprintf(char *buf, size_t size, const char *fmt, ...); +YAZ_EXPORT void yaz_vsnprintf(char *buf, size_t size, const char *fmt, + va_list ap); + +YAZ_END_CDECL + +#endif +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/Makefile.am b/src/Makefile.am index 5aceac1..41c84ff 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ ## This file is part of the YAZ toolkit. ## Copyright (C) 1995-2007, Index Data, All rights reserved. -## $Id: Makefile.am,v 1.51 2007-01-11 10:55:57 adam Exp $ +## $Id: Makefile.am,v 1.52 2007-02-23 10:15:01 adam Exp $ YAZ_VERSION_INFO=2:1:0 @@ -81,7 +81,7 @@ libyaz_la_SOURCES=version.c options.c log.c \ eventl.h service.c service.h session.h test.c timing.c \ xmlquery.c http.c \ mime.c mime.h \ - record_conv.c retrieval.c elementset.c + record_conv.c retrieval.c elementset.c snprintf.c libyaz_la_LDFLAGS=-version-info $(YAZ_VERSION_INFO) diff --git a/src/libxml2_error.c b/src/libxml2_error.c index 725b7cf..e5b5ce0 100644 --- a/src/libxml2_error.c +++ b/src/libxml2_error.c @@ -2,7 +2,7 @@ * Copyright (C) 2007, Index Data ApS * See the file LICENSE for details. * - * $Id: libxml2_error.c,v 1.3 2007-01-03 08:42:15 adam Exp $ + * $Id: libxml2_error.c,v 1.4 2007-02-23 10:15:01 adam Exp $ */ /** * \file libxml2_error.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #if YAZ_HAVE_XML2 @@ -31,11 +32,7 @@ static void proxy_xml_error_handler(void *ctx, const char *fmt, ...) va_list ap; va_start(ap, fmt); -#ifdef WIN32 - vsprintf(buf, fmt, ap); -#else - vsnprintf(buf, sizeof(buf), fmt, ap); -#endif + yaz_vsnprintf(buf, sizeof(buf)-1, fmt, ap); yaz_log(libxml2_error_level, "%s: %s", (char*) ctx, buf); va_end (ap); diff --git a/src/log.c b/src/log.c index ed2e05e..351c0bd 100644 --- a/src/log.c +++ b/src/log.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: log.c,v 1.47 2007-02-20 09:39:17 adam Exp $ + * $Id: log.c,v 1.48 2007-02-23 10:15:01 adam Exp $ */ /** @@ -36,6 +36,7 @@ #include #include #include +#include #include static NMEM_MUTEX log_mutex = 0; @@ -472,17 +473,8 @@ void yaz_log(int level, const char *fmt, ...) if (!(level & l_level)) return; va_start(ap, fmt); -#ifdef WIN32 - _vsnprintf(buf, sizeof(buf)-1, fmt, ap); -#else -/* !WIN32 */ -#if HAVE_VSNPRINTF - vsnprintf(buf, sizeof(buf), fmt, ap); -#else - vsprintf(buf, fmt, ap); -#endif -#endif -/* WIN32 */ + + yaz_vsnprintf(buf, sizeof(buf)-1, fmt, ap); if (o_level & YLOG_ERRNO) { strcat(buf, " ["); diff --git a/src/marcdisp.c b/src/marcdisp.c index 9037b5b..6eeccb3 100644 --- a/src/marcdisp.c +++ b/src/marcdisp.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: marcdisp.c,v 1.46 2007-02-17 10:53:05 adam Exp $ + * $Id: marcdisp.c,v 1.47 2007-02-23 10:15:01 adam Exp $ */ /** @@ -26,6 +26,7 @@ #include #include #include +#include #if YAZ_HAVE_XML2 #include @@ -174,19 +175,9 @@ void yaz_marc_cprintf(yaz_marc_t mt, const char *fmt, ...) { va_list ap; char buf[200]; - va_start(ap, fmt); -#ifdef WIN32 - _vsnprintf(buf, sizeof(buf)-1, fmt, ap); -#else -/* !WIN32 */ -#if HAVE_VSNPRINTF - vsnprintf(buf, sizeof(buf), fmt, ap); -#else - vsprintf(buf, fmt, ap); -#endif -#endif -/* WIN32 */ + va_start(ap, fmt); + yaz_vsnprintf(buf, sizeof(buf)-1, fmt, ap); yaz_marc_add_comment(mt, buf); va_end (ap); } diff --git a/src/odr.c b/src/odr.c index 30b08c8..645317e 100644 --- a/src/odr.c +++ b/src/odr.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: odr.c,v 1.14 2007-01-03 08:42:15 adam Exp $ + * $Id: odr.c,v 1.15 2007-02-23 10:15:01 adam Exp $ * */ @@ -22,6 +22,7 @@ #include #include +#include #include "odr-priv.h" static int log_level=0; @@ -295,15 +296,7 @@ void odr_printf(ODR o, const char *fmt, ...) char buf[4096]; va_start(ap, fmt); -#ifdef WIN32 - _vsnprintf(buf, sizeof(buf)-1, fmt, ap); -#else -#if HAVE_VSNPRINTF - vsnprintf(buf, sizeof(buf), fmt, ap); -#else - vsprintf(buf, fmt, ap); -#endif -#endif + yaz_vsnprintf(buf, sizeof(buf), fmt, ap); o->op->stream_write(o, o->print, ODR_VISIBLESTRING, buf, strlen(buf)); va_end(ap); } diff --git a/src/snprintf.c b/src/snprintf.c new file mode 100644 index 0000000..fccf3b0 --- /dev/null +++ b/src/snprintf.c @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2007, Index Data ApS + * See the file LICENSE for details. + * + * $Id: snprintf.c,v 1.1 2007-02-23 10:15:01 adam Exp $ + */ +/** + * \file snprintf.c + * \brief snprintf wrapper + */ + +#include +#include +#include + +void yaz_vsnprintf(char *buf, size_t size, const char *fmt, va_list ap) +{ +#if HAVE_VSNPRINF + vsnprintf(buf, size, fmt, ap); +#else +#ifdef WIN32 + _vsnprintf(buf, size, fmt, ap); +#else + vsprintf(buf, fmt, ap); +#endif +#endif +} + +void yaz_snprintf(char *buf, size_t size, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + yaz_vsnprintf(buf, size, fmt, ap); + va_end(ap); +} + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/wrbuf.c b/src/wrbuf.c index fb5968b..e8e6434 100644 --- a/src/wrbuf.c +++ b/src/wrbuf.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: wrbuf.c,v 1.15 2007-01-06 16:05:24 adam Exp $ + * $Id: wrbuf.c,v 1.16 2007-02-23 10:15:01 adam Exp $ */ /** @@ -20,6 +20,7 @@ #include #include +#include #include WRBUF wrbuf_alloc(void) @@ -159,16 +160,7 @@ void wrbuf_printf(WRBUF b, const char *fmt, ...) char buf[4096]; va_start(ap, fmt); -#ifdef WIN32 - _vsnprintf(buf, sizeof(buf)-1, fmt, ap); -#else -/* !WIN32 */ -#if HAVE_VSNPRINTF - vsnprintf(buf, sizeof(buf)-1, fmt, ap); -#else - vsprintf(buf, fmt, ap); -#endif -#endif + yaz_vsnprintf(buf, sizeof(buf)-1, fmt, ap); wrbuf_puts (b, buf); va_end(ap); diff --git a/win/makefile b/win/makefile index cda5048..ab48fca 100644 --- a/win/makefile +++ b/win/makefile @@ -1,6 +1,6 @@ # Copyright (C) 1995-2007, Index Data ApS # All rights reserved. -# $Id: makefile,v 1.128 2007-01-24 11:50:19 adam Exp $ +# $Id: makefile,v 1.129 2007-02-23 10:15:02 adam Exp $ # # Programmed by # Heikki Levanto & Adam Dickmeiss @@ -386,6 +386,7 @@ MISC_OBJS= \ $(OBJDIR)\xmalloc.obj \ $(OBJDIR)\matchstr.obj \ $(OBJDIR)\siconv.obj \ + $(OBJDIR)\snprintf.obj \ $(OBJDIR)\marc8.obj \ $(OBJDIR)\marc8r.obj \ $(OBJDIR)\record_conv.obj \ -- 1.7.10.4