3 /* Copyright (C) 2002 Brad Jorsch <anomie@users.sourceforge.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 #if defined(HAVE_WORKING_VSNPRINTF)
29 /* vsnprintf works, nothing to do */
31 #elif !defined(VSNPRINTF_BOGUS_RETVAL)
33 /* vsnprintf is b0rken, but the return value is ok (thus, the only problem is
36 int rpl_vsnprintf(char *str
, size_t size
, const char *format
, va_list ap
){
37 if(str
==NULL
|| size
==0){{
39 return vsnprintf(foo
, 3, format
, ap
);
41 return vsnprintf(str
, size
, format
, ap
);
45 #elif !defined(VSNPRINTF_IS_VSPRINTF) && defined(HAVE_VPRINTF)
47 /* vsnprintf's retval is bogus, so we compensate. */
53 # define va_copy(dest, src) __va_copy(dest, src)
56 # define va_copy(dest, src) memcpy(&dest, &src, sizeof(va_list))
60 int rpl_vsnprintf(char *str
, size_t size
, const char *format
, va_list ap
){
66 #ifdef VSNPRINTF_NULL_OK
67 vsnprintf(str
, size
, format
, ap
);
69 if(str
==NULL
|| size
==0){{
71 vsnprintf(foo
, 3, format
, ap
);
73 vsnprintf(str
, size
, format
, ap
);
78 if((devnull
=fopen("/dev/null", "w"))==NULL
){
79 perror("Couldn't open /dev/null for writing");
84 r
=vfprintf(devnull
, format
, ap2
);
91 /* OK, we're screwed */
93 # error "vsnprintf is so broken we can't compensate. Sorry."