/*
* Copyright (c) 1995 Patrick Powell.
*
* This code is based on code written by Patrick Powell <papowell@astart.com>.
* It may be used for any purpose as long as this notice remains intact on all
* source code distributions.
*/
/*
* Copyright (c) 2008 Holger Weiss.
*
* This version of the code is maintained by Holger Weiss <holger@jhweiss.de>.
* My changes to the code may freely be used, modified and/or redistributed for
* any purpose. It would be nice if additions and fixes to this file (including
* trivial code cleanups) would be sent back in order to let me include them in
* the version available at <http://www.jhweiss.de/software/snprintf.html>.
* However, this is not a requirement for using or redistributing (possibly
* modified) versions of this file, nor is leaving this notice intact mandatory.
*/
/*
* History
*
* 2008-01-20 Holger Weiss <holger@jhweiss.de> for C99-snprintf 1.1:
*
* Fixed the detection of infinite floating point values on IRIX (and
* possibly other systems) and applied another few minor cleanups.
*
* 2008-01-06 Holger Weiss <holger@jhweiss.de> for C99-snprintf 1.0:
*
* Added a lot of new features, fixed many bugs, and incorporated various
* improvements done by Andrew Tridgell <tridge@samba.org>, Russ Allbery
* <rra@stanford.edu>, Hrvoje Niksic <hniksic@xemacs.org>, Damien Miller
* <djm@mindrot.org>, and others for the Samba, INN, Wget, and OpenSSH
* projects. The additions include: support the "e", "E", "g", "G", and
* "F" conversion specifiers (and use conversion style "f" or "F" for the
* still unsupported "a" and "A" specifiers); support the "hh", "ll", "j",
* "t", and "z" length modifiers; support the "#" flag and the (non-C99)
* "'" flag; use localeconv(3) (if available) to get both the current
* locale's decimal point character and the separator between groups of
* digits; fix the handling of various corner cases of field width and
* precision specifications; fix various floating point conversion bugs;
* handle infinite and NaN floating point values; don't attempt to write to
* the output buffer (which may be NULL) if a size of zero was specified;
* check for integer overflow of the field width, precision, and return
* values and during the floating point conversion; use the OUTCHAR() macro
* instead of a function for better performance; provide asprintf(3) and
* vasprintf(3) functions; add new test cases. The replacement functions
* have been renamed to use an "rpl_" prefix, the function calls in the
* main project (and in this file) must be redefined accordingly for each
* replacement function which is needed (by using Autoconf or other means).
* Various other minor improvements have been applied and the coding style
* was cleaned up for consistency.
*
* 2007-07-23 Holger Weiss <holger@jhweiss.de> for Mutt 1.5.13:
*
* C99 compliant snprintf(3) and vsnprintf(3) functions return the number
* of characters that would have been written to a sufficiently sized
* buffer (excluding the '\0'). The original code simply returned the
* length of the resulting output string, so that's been fixed.
*
* 1998-03-05 Michael Elkins <me@mutt.org> for Mutt 0.90.8:
*
* The original code assumed that both snprintf(3) and vsnprintf(3) were
* missing. Some systems only have snprintf(3) but not vsnprintf(3), so
* the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF.
*
* 1998-01-27 Thomas Roessler <roessler@does-not-exist.org> for Mutt 0.89i:
*
* The PGP code was using unsigned hexadecimal formats. Unfortunately,
* unsigned formats simply didn't work.
*
* 1997-10-22 Brandon Long <blong@fiction.net> 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, formatted the code to Mutt conventions, and removed dead code left
* over from the original. Also, there is now a builtin-test, run with:
* gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm && ./snprintf
*
* 2996-09-15 Brandon Long <blong@fiction.net> for Mutt 0.43:
*
* This was ugly. It is still ugly. I opted out of floating point
* numbers, but the formatter understands just about everything from the
* normal C string format, at least as far as I can tell from the Solaris
* 2.5 printf(3S) man page.
*/
/*
* ToDo
*
* - Add wide character support.
* - Add support for "%a" and "%A" conversions.
* - Create test routines which predefine the expected results. Our test cases
* usually expose bugs in system implementations rather than in ours :-)
*/
/*
* Usage
*
* 1) The following preprocessor macros should be defined to 1 if the feature or
* file in question is available on the target system (by using Autoconf or
* other means), though basic functionality should be available as long as
* HAVE_STDARG_H and HAVE_STDLIB_H are defined correctly:
*
* HAVE_VSNPRINTF
* HAVE_SNPRINTF
* HAVE_VASPRINTF
* HAVE_ASPRINTF
* HAVE_STDARG_H
* HAVE_STDDEF_H
* HAVE_STDINT_H
* HAVE_STDLIB_H
* HAVE_INTTYPES_H
* HAVE_LOCALE_H
* HAVE_LOCALECONV
* HAVE_LCONV_DECIMAL_POINT
* HAVE_LCONV_THOUSANDS_SEP
* HAVE_LONG_DOUBLE
* HAVE_LONG_LONG_INT
* HAVE_UNSIGNED_LONG_LONG_INT
* HAVE_INTMAX_T
* HAVE_UINTMAX_T
* HAVE_UINTPTR_T
* HAVE_PTRDIFF_T
* HAVE_VA_COPY
* HAVE___VA_COPY
*
* 2) The calls to the functions which should be replaced must be redefined
* throughout the project files (by using Autoconf or other means):
*
* #define vsnprintf rpl_vsnprintf
* #define snprintf rpl_snprintf
* #define vasprintf rpl_vasprintf
* #define asprintf rpl_asprintf
*
* 3) The required replacement functions should be declared in some header file
* included throughout the project files:
*
* #if HAVE_CONFIG_H
* #include <config.h>
* #endif
* #if HAVE_STDARG_H
* #include <stdarg.h>
* #if !HAVE_VSNPRINTF
* int rpl_vsnprintf(char *, size_t, const char *, va_list);
* #endif
* #if !HAVE_SNPRINTF
* int rpl_snprintf(char *, size_t, const char *, ...);
* #endif
* #if !HAVE_VASPRINTF
* int rpl_vasprintf(char **, const char *, va_list);
* #endif
* #if !HAVE_ASPRINTF
* int rpl_asprintf(char **, const char *, ...);
* #endif
* #endif
*
* Autoconf macros for handling step 1 and step 2 are available at
* <http://www.jhweiss.de/software/snprintf.html>.
*/
#include "pipe/p_config.h"
#if HAVE_CONFIG_H
#include <config.h>
#else
#ifdef WIN32
#define vsnprintf util_vsnprintf
#define snprintf util_snprintf
#define HAVE_VSNPRINTF 0
#define HAVE_SNPRINTF 0
#define HAVE_VASPRINTF 1 /* not needed */
#define HAVE_ASPRINTF 1 /* not needed */
#define HAVE_STDARG_H 1
#define HAVE_STDDEF_H 1
#define HAVE_STDINT_H 0
#define HAVE_STDLIB_H 1
#define HAVE_INTTYPES_H 0
#define HAVE_LOCALE_H 0
#define HAVE_LOCALECONV 0
#define HAVE_LCONV_DECIMAL_POINT 0
#define HAVE_LCONV_THOUSANDS_SEP 0
#define HAVE_LONG_DOUBLE 0
#define HAVE_LONG_LONG_INT 1
#define HAVE_UNSIGNED_LONG_LONG_INT 1
#define HAVE_INTMAX_T 0
#define HAVE_UINTMAX_T 0
#define HAVE_UINTPTR_T 1
#define HAVE_PTRDIFF_T 1
#define HAVE_VA_COPY 0
#define HAVE___VA_COPY 0
#else
#define HAVE_VSNPRINTF 1
#define HAVE_SNPRINTF 1
#define HAVE_VASPRINTF 1
#define HAVE_ASPRINTF 1
#endif
#endif /* HAVE_CONFIG_H */
#if !HAVE_SNPRINTF || !HAVE_VSNPRINTF || !HAVE_ASPRINTF || !HAVE_VASPRINTF
#include <stdio.h> /* For NULL, size_t, vsnprintf(3), and vasprintf(3). */
#ifdef VA_START
#undef VA_START
#endif /* defined(VA_START) */
#ifdef VA_SHIFT
#undef VA_SHIFT
#endif /* defined(VA_SHIFT) */
#if HAVE_STDARG_H
#include <stdarg.h>
#define VA_START(ap, last) va_start(ap, last)
#
mutex-debug.rar_floating
版权申诉
116 浏览量
2022-09-24
07:16:03
上传
评论
收藏 12KB RAR 举报
![avatar](https://profile-avatar.csdnimg.cn/dabc422b995e4f93b0df429caef6266e_weixin_42656416.jpg!1)
四散
- 粉丝: 54
- 资源: 1万+