X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fportab%2Fvsnprintf.c;h=3f9707b7a65affa657477c75aa8e132db7fe5d82;hb=b90f71ca2ab1b2eea7ca992b1e51a4b39afe0728;hp=8620164ff7e24d38a3fd7f2b9dee7119be68850f;hpb=679565603aebc3880fe640301ac8216811da5d32;p=ngircd-alex.git diff --git a/src/portab/vsnprintf.c b/src/portab/vsnprintf.c index 8620164f..3f9707b7 100644 --- a/src/portab/vsnprintf.c +++ b/src/portab/vsnprintf.c @@ -2,20 +2,20 @@ * ngIRCd -- The Next Generation IRC Daemon * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de) * - * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen - * der GNU General Public License (GPL), wie von der Free Software Foundation - * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2 - * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version. - * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste - * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * Please read the file COPYING, README and AUTHORS for more information. * - * $Id: vsnprintf.c,v 1.1 2002/05/19 01:17:40 alex Exp $ - * - * vsnprintf.c: vsnprintf()-Ersatz + * snprintf() and vsnprintf() replacement functions */ #include "portab.h" + +static char UNUSED id[] = "$Id: vsnprintf.c,v 1.5 2003/04/21 10:53:38 alex Exp $"; + #include "imp.h" #include "exp.h" @@ -45,33 +45,36 @@ * from the normal C string format, at least as far as I can tell from * the Solaris 2.5 printf(3S) man page. * - * Brandon Long 10/22/97 for mutt 0.87.1 - * Ok, added some minimal floating point support, which means this - * probably requires libm on most operating systems. Don't yet - * support the exponent (e,E) and sigfig (g,G). Also, fmtint() - * was pretty badly broken, it just wasn't being exercised in ways - * which showed it, so that's been fixed. Also, formated the code - * to mutt conventions, and removed dead code left over from the - * original. Also, there is now a builtin-test, just compile with: - * gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm - * and run snprintf for results. + * Brandon Long 10/22/97 for mutt 0.87.1 + * Ok, added some minimal floating point support, which means this + * probably requires libm on most operating systems. Don't yet + * support the exponent (e,E) and sigfig (g,G). Also, fmtint() + * was pretty badly broken, it just wasn't being exercised in ways + * which showed it, so that's been fixed. Also, formated the code + * to mutt conventions, and removed dead code left over from the + * original. Also, there is now a builtin-test, just compile with: + * gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm + * and run snprintf for results. * - * Thomas Roessler 01/27/98 for mutt 0.89i - * The PGP code was using unsigned hexadecimal formats. - * Unfortunately, unsigned formats simply didn't work. + * Thomas Roessler 01/27/98 for mutt 0.89i + * The PGP code was using unsigned hexadecimal formats. + * Unfortunately, unsigned formats simply didn't work. * - * Michael Elkins 03/05/98 for mutt 0.90.8 - * The original code assumed that both snprintf() and vsnprintf() were - * missing. Some systems only have snprintf() but not vsnprintf(), so - * the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF. + * Michael Elkins 03/05/98 for mutt 0.90.8 + * The original code assumed that both snprintf() and vsnprintf() were + * missing. Some systems only have snprintf() but not vsnprintf(), so + * the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF. * - * Andrew Tridgell (tridge@samba.org) Oct 1998 - * fixed handling of %.0f - * added test for HAVE_LONG_DOUBLE + * Andrew Tridgell , October 1998 + * fixed handling of %.0f + * added test for HAVE_LONG_DOUBLE * * tridge@samba.org, idra@samba.org, April 2001 - * got rid of fcvt code (twas buggy and made testing harder) - * added C99 semantics + * got rid of fcvt code (twas buggy and made testing harder) + * added C99 semantics + * + * Alexander Barton, , 2002-05-19 + * removed [v]asprintf() and C99 tests: not needed by ngIRCd. */ @@ -90,11 +93,13 @@ #include #endif -#if defined(HAVE_SNPRINTF) && defined(HAVE_VSNPRINTF) && defined(HAVE_C99_VSNPRINTF) + +#if defined(HAVE_SNPRINTF) && defined(HAVE_VSNPRINTF) /* only include stdio.h if we are not re-defining snprintf or vsnprintf */ #include - /* make the compiler happy with an empty file */ - void dummy_snprintf(void) {} +/* make the compiler happy with an empty file */ +void dummy_snprintf PARAMS(( void )); +void dummy_snprintf PARAMS(( void )) { } #else #ifdef HAVE_LONG_DOUBLE @@ -643,7 +648,7 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, #endif #if 0 - if (max == 0) ufvalue += 0.5; /* if max = 0 we must round */ + if (max == 0) ufvalue += 0.5; /* if max = 0 we must round */ #endif /* @@ -763,15 +768,15 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) (*currlen)++; } -#if !defined(HAVE_VSNPRINTF) || !defined(HAVE_C99_VSNPRINTF) - int vsnprintf (char *str, size_t count, const char *fmt, va_list args) +#if !defined(HAVE_VSNPRINTF) +int vsnprintf (char *str, size_t count, const char *fmt, va_list args) { return dopr(str, count, fmt, args); } #endif -#if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF) - int snprintf(char *str,size_t count,const char *fmt,...) +#if !defined(HAVE_SNPRINTF) +int snprintf(char *str,size_t count,const char *fmt,...) { size_t ret; va_list ap; @@ -783,39 +788,9 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) } #endif -#endif - -#ifndef HAVE_VASPRINTF - int vasprintf(char **ptr, const char *format, va_list ap) -{ - int ret; - - ret = vsnprintf(NULL, 0, format, ap); - if (ret <= 0) return ret; - - (*ptr) = (char *)malloc(ret+1); - if (!*ptr) return -1; - ret = vsnprintf(*ptr, ret+1, format, ap); - - return ret; -} #endif -#ifndef HAVE_ASPRINTF - int asprintf(char **ptr, const char *format, ...) -{ - va_list ap; - int ret; - - va_start(ap, format); - ret = vasprintf(ptr, format, ap); - va_end(ap); - - return ret; -} -#endif - #ifdef TEST_SNPRINTF int sprintf(char *str,const char *fmt,...); int main (void)