From dbac6fe2830f3ecacc09be5f3e722b5806fab4c7 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 7 Jan 2022 11:54:54 -0500 Subject: [PATCH] Removed the local implementation of snprintf() and vsnprintf() that we hacked in two decades ago to work around broken or missing system libraries. Not needed anymore. --- citadel/snprintf.c | 79 ---------------------------------------------- citadel/snprintf.h | 11 ------- 2 files changed, 90 deletions(-) delete mode 100644 citadel/snprintf.c delete mode 100644 citadel/snprintf.h diff --git a/citadel/snprintf.c b/citadel/snprintf.c deleted file mode 100644 index ad04a02e2..000000000 --- a/citadel/snprintf.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Replacements for snprintf() and vsnprintf() - * - * modified from Sten Gunterberg's BUGTRAQ post of 22 Jul 1997 - * --nathan bryant - * - * Use it only if you have the "spare" cycles needed to effectively - * do every snprintf operation twice! Why is that? Because everything - * is first vfprintf()'d to /dev/null to determine the number of bytes. - * Perhaps a bit slow for demanding applications on slow machines, - * no problem for a fast machine with some spare cycles. - * - * You don't have a /dev/null? Every Linux contains one for free! - * - * Because the format string is never even looked at, all current and - * possible future printf-conversions should be handled just fine. - * - * Written July 1997 by Sten Gunterberg (gunterberg@ergon.ch) - */ - -#include -#include -#include -#include - -static int -needed (const char *fmt, va_list argp) -{ - static FILE *sink = NULL; - - /* ok, there's a small race here that could result in the sink being - * opened more than once if we're threaded, but I'd rather ignore it than - * spend cycles synchronizing :-) */ - - if (sink == NULL) - { - if ((sink = fopen("/dev/null", "w")) == NULL) - { - perror("/dev/null"); - exit(1); - } - } - - return vfprintf(sink, fmt, argp); -} - -int -vsnprintf (char *buf, size_t max, const char *fmt, va_list argp) -{ - char *p; - int size; - - if ((p = malloc(needed(fmt, argp) + 1)) == NULL) - { - fprintf(stderr, "vsnprintf: malloc failed, aborting\n"); - abort(); - } - - if ((size = vsprintf(p, fmt, argp)) >= max) - size = -1; - - strncpy(buf, p, max); - buf[max - 1] = 0; - free(p); - return size; -} - -int -snprintf (char *buf, size_t max, const char *fmt, ...) -{ - va_list argp; - int bytes; - - va_start(argp, fmt); - bytes = vsnprintf(buf, max, fmt, argp); - va_end(argp); - - return bytes; -} diff --git a/citadel/snprintf.h b/citadel/snprintf.h deleted file mode 100644 index 9cabca4e5..000000000 --- a/citadel/snprintf.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __DECC - -#ifdef __GNUC__ -int snprintf (char *buf, size_t max, const char *fmt, ...) __attribute__((__format__(__printf__,3,4))); -int vsnprintf (char *buf, size_t max, const char *fmt, va_list argp) __attribute__((__format__(__printf__,3,0))); -#else -int snprintf (char *buf, size_t max, const char *fmt, ...); -int vsnprintf (char *buf, size_t max, const char *fmt, va_list argp); -#endif - -#endif -- 2.39.2