From 447f21bc3e77d0dd3710df85e028ba7e2f5db236 Mon Sep 17 00:00:00 2001 From: Robert Spalek Date: Wed, 10 Jul 2002 14:47:26 +0000 Subject: [PATCH 1/1] added v?xprintf() functions, they will be used in the filter dumper it is usable, for example, for printf()'ing to anything (like fastbufs) --- lib/Makefile | 2 +- lib/printf.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ lib/printf.h | 17 +++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 lib/printf.c create mode 100644 lib/printf.h diff --git a/lib/Makefile b/lib/Makefile index c6ef7e94..631a7437 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -8,7 +8,7 @@ SHLIB_OBJS=alloc.o alloc_str.o ctmatch.o db.o fastbuf.o fb-file.o fb-mem.o lists prime.o random.o realloc.o regex.o timer.o url.o wildmatch.o \ wordsplit.o str_ctype.o str_upper.o bucket.o conf.o object.o sorter.o \ finger.o proctitle.o ipaccess.o profile.o bitsig.o randomkey.o \ - hashfunc.o base224.o fb-temp.o + hashfunc.o base224.o fb-temp.o printf.o obj/lib/libsh.a: $(addprefix obj/lib/,$(SHLIB_OBJS)) $(CUSTOM_MODULES) diff --git a/lib/printf.c b/lib/printf.c new file mode 100644 index 00000000..f8c801f0 --- /dev/null +++ b/lib/printf.c @@ -0,0 +1,47 @@ +/* + * Sherlock Library -- auto-resizable printf() functions + * + * (c) 2002, Robert Spalek + */ + +#include "lib/lib.h" +#include "lib/printf.h" + +#include + +byte * +vxprintf(char *msg, va_list v) +{ + static byte *buf = NULL; + static int buf_len = 0; + int len; + if (!buf) + { + buf_len = 1024; + buf = xmalloc(buf_len); + } + while (1) + { + len = vsnprintf(buf, buf_len, msg, v); + if (len >= 0 && len < buf_len) + return buf; + else + { + buf_len *= 2; + if (len >= buf_len) + buf_len = len + 1; + buf = xrealloc(buf, buf_len); + } + } +} + +byte * +xprintf(char *msg, ...) +{ + byte *txt; + va_list v; + va_start(v, msg); + txt = vxprintf(msg, v); + va_end(v); + return txt; +} diff --git a/lib/printf.h b/lib/printf.h new file mode 100644 index 00000000..c0d26bcd --- /dev/null +++ b/lib/printf.h @@ -0,0 +1,17 @@ +/* + * Sherlock Library -- auto-resizable printf() functions + * + * (c) 2002, Robert Spalek + */ + +#ifndef _LIB_PRINTF_H +#define _LIB_PRINTF_H + +#include + +/* The following functions are NOT reentrable. */ + +byte *vxprintf(char *msg, va_list v); +byte *xprintf(char *msg, ...) __attribute__((format(printf,1,2))); + +#endif -- 2.39.2