Home Software
RADIUS Plugin
ZUPS Daemon Deletemail PPP Usage C99‑snprintf Nagios Stuff OSBF‑Lua Stuff Mutt Patches Qmail Patches Misc Snippets Contact
|
C99-snprintfOverviewC99‑snprintf provides a portable implementation of snprintf(3),
vsnprintf(3),
asprintf(3),
and vasprintf(3).
It should be fully C99
compliant, with the exceptions that it doesn't provide wide
character support and that The snprintf(3) and vsnprintf(3) functions are part of the C99 standard library. However, they weren't included in the C89/C90 standards and some systems don't provide C99 compliant implementations of these functions. For example, if the ouput buffer isn't big enough to hold the full conversion result, IRIX up to the current release 6.5.30 and glibc up to 2.0.x don't return the same value as with a sufficiently sized buffer (which makes it impossible to precompute the required buffer size), and some older systems (such as 64-bit Solaris 7) ignore the specified buffer size and overrun the buffer if it's too small. The asprintf(3) and vasprintf(3) functions aren't standardized at all. They're included with recent releases of glibc and BSD's libc, but they aren't available on other systems, such as System V (e.g., Solaris). So, if any of these functions are used, portable software should include replacement code which is used in case the functions aren't available or don't work correctly on the target system. C99‑snprintf can be included with software packages in order to provide such replacement functions. Download
UsageWith GNU Autoconf 2.60 or newer
Without GNU AutoconfIf you're not using GNU Autoconf, omit the steps 2 and 3 from the above instructions. Instead:
History2008-01-20 Holger Weiß for C99-snprintf 1.1Fixed the detection of infinite floating point values on IRIX (and possibly other systems) and applied another few minor cleanups. 2008-01-04 Holger Weiß for C99-snprintf 1.0Added a lot of new features, fixed many bugs, and incorporated
various improvements done by Andrew Tridgell, Russ Allbery,
Hrvoje Niksic, Damien Miller, and others for the Samba, INN, Wget, and OpenSSH projects. The
additions include: support the 2007-07-23 Holger Weiß for Mutt 1.5.13C99 compliant snprintf(3) and vsnprintf(3) functions return the
number of characters that would have been written to a
sufficiently sized buffer (excluding the 1998-03-05 Michael Elkins for Mutt 0.90.8The 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
1998-01-27 Thomas Roessler for Mutt 0.89iThe PGP code was using unsigned hexadecimal formats. Unfortunately, unsigned formats simply didn't work. 1997-10-22 Brandon Long for Mutt 0.87.1Ok, added some minimal floating point support, which means this
probably requires libm on most operating systems. Don't yet
support the exponent
( 2996-09-15 Brandon Long for Mutt 0.43This 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. Bugs and CaveatsDepending on the size of the largest integer type available on the target platform, floating point precisions larger than 9, 19, or 38 are not supported. If a larger precision is specified, it will silently be reduced to the largest possible precision on the target system. If the integral part of a floating point value doesn't fit into
the largest integer type available on the target platform, the
conversion will fail. In this case, C99‑snprintf
will return C99‑snprintf makes a few assumptions regarding integer (and pointer value) conversions which aren't backed by the C standard, but which should be safe in practice. Copyright and LicenseCopyright © 2008 Holger Weiß. 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. NewsletterIf you want to be informed about new C99-snprintf releases, you can subscribe to this project on freshmeat. You will then receive an e-mail as soon as a new C99-snprintf release is available, including a short summary of the changes. FeedbackFeel free to drop me an e-mail if you encounter any problems with or have any comments on C99‑snprintf. Other ImplementationsSee Mark Martinec's portable snprintf(3) page for an extensive link collection and especially James Antill's very good printf() implementation comparison. Last modified: $Date: 2020/08/21 07:04:25 $ by Holger Weiß |