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)
--- /dev/null
+/*
+ * Sherlock Library -- auto-resizable printf() functions
+ *
+ * (c) 2002, Robert Spalek <robert@ucw.cz>
+ */
+
+#include "lib/lib.h"
+#include "lib/printf.h"
+
+#include <stdio.h>
+
+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;
+}
--- /dev/null
+/*
+ * Sherlock Library -- auto-resizable printf() functions
+ *
+ * (c) 2002, Robert Spalek <robert@ucw.cz>
+ */
+
+#ifndef _LIB_PRINTF_H
+#define _LIB_PRINTF_H
+
+#include <stdarg.h>
+
+/* The following functions are NOT reentrable. */
+
+byte *vxprintf(char *msg, va_list v);
+byte *xprintf(char *msg, ...) __attribute__((format(printf,1,2)));
+
+#endif