History log of /freebsd-current/lib/libc/stdio/vfprintf.c
Revision Date Author Comments
# f8876676 23-Apr-2024 Konstantin Belousov <kib@FreeBSD.org>

__vprintf(): switch from strerror() to strerror_rl()

This eliminates the use of non-thread-safe function in printf*() family,
and make the call locale-aware. Also, it stops obliterating the
strerror() static buffer, which aligns with the POSIX requirement that
implementations must behave as if no standard-mandated functions call
strerror().

PR: 278556
Reported by: Jonathan Gruber <jonathan.gruber.jg@gmail.com>
Reviewed by: imp
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D44916


# dc36d6f9 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

lib: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 559a218c 01-Nov-2023 Warner Losh <imp@FreeBSD.org>

libc: Purge unneeded cdefs.h

These sys/cdefs.h are not needed. Purge them. They are mostly left-over
from the $FreeBSD$ removal. A few in libc are still required for macros
that cdefs.h defines. Keep those.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D42385


# bce0bef3 07-Sep-2023 Dag-Erling Smørgrav <des@FreeBSD.org>

libc: Implement N2680.

This adds specific width length modifiers in the form of wN and wfN (where N is 8, 16, 32, or 64) which allow printing intN_t and int_fastN_t without resorting to casts or PRI macros.

Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D41725


# d9dc1603 28-Aug-2023 Dag-Erling Smørgrav <des@FreeBSD.org>

libc: Implement N2630.

This adds formatted input/output of binary integer numbers to the printf(), scanf(), and strtol() families, including their wide-character counterparts.

Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D41511


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 5b5fa75a 04-Aug-2022 Ed Maste <emaste@FreeBSD.org>

libc: drop "All rights reserved" from Foundation copyrights

This has already been done for most files that have the Foundation as
the only listed copyright holder. Do it now for files that list
multiple copyright holders, but have the Foundation copyright in its own
section.

Sponsored by: The FreeBSD Foundation


# e95725fe 22-May-2018 Konstantin Belousov <kib@FreeBSD.org>

Implement printf(3) family %m format string extension.

Reviewed by: ed, dim (code only)
Sponsored by: Mellanox Technologies
MFC after: 1 week


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

General further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.


# fda0a14f 29-Jun-2017 Konstantin Belousov <kib@FreeBSD.org>

Make stdio deferred cancel-safe.

If used with fopen(3)/fdopen(3)-ed FILEs, stdio accurately uses
non-cancellable internal versions of the functions, i.e. it seems to
be fine with regard to cancellation. But if the funopen(3) and
f{r,w}open(3) functions were used to open the FILE, and corresponding
user functions create cancellation points (they typically have no
other choice), then stdio code at least leaks FILE' lock.

The change installs cleanup handler which unlocks FILE. Some minimal
restructuring of the code was required to make it use common return
place to satisfy hand-rolled pthread_cleanup_pop() requirements.

Noted by: eugen
Reviewed by: eugen, vangyzen
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Differential revision: https://reviews.freebsd.org/D11246


# 7c39dd2e 22-Dec-2016 Enji Cooper <ngie@FreeBSD.org>

Revert r310138

Adding %b support to vfprintf for parity with kernel space requires
more discussion/review.

In particular, many parties were concerned over introducing a
non-standard format qualifier to *printf(3) which didn't already
exist in other OSes, e.g. Linux, thus making code which used %b
harder to port to other operating systems.

Requested by: many


# ec055aef 15-Dec-2016 Conrad Meyer <cem@FreeBSD.org>

vfprintf(3): Add support for kernel %b format

This is a direct port of the kernel %b format.

I'm unclear on if (more) non-portable printf extensions will be a
problem. I think it's desirable to have userspace formats include all
kernel formats, but there may be competing goals I'm not aware of.

Reviewed by: no one, unfortunately
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D8426


# 1bf6c5f1 25-Aug-2016 Andrey A. Chernov <ache@FreeBSD.org>

Don't check for __SERR which may stick from one of any previous stdio
functions.
__SERR is for user and the rest of stdio code do not check it
for error sensing internally, only set it.
In vf(w)printf.c here it is more easy to save __SERR, clear and restore it.


# 450ead86 20-Jul-2014 Pedro F. Giffuni <pfg@FreeBSD.org>

Adjust errno on failed prepwrite.

Obtained from: Apple Inc. (Libc 997.90.3)
Phabric: D442
MFC after: 1 week


# 1d8053c5 23-Apr-2013 Ed Maste <emaste@FreeBSD.org>

Renumber clauses to reduce diffs to other versions

NetBSD, OpenBSD, and Android's Bionic all number the clauses 1 through 3,
so follow suit to make comparison easier.

Acked-by: imp@


# 666d00d3 21-Apr-2012 David Schultz <das@FreeBSD.org>

If the size passed to {,v}s{w,n}printf is larger than INT_MAX+1
(i.e., the return value would overflow), set errno to EOVERFLOW
and return an error. This improves the chances that buggy
applications -- for instance, ones that pass in a negative integer
as the size due to a bogus calculation -- will fail in safe ways.
Returning an error in these situations is specified by POSIX, but
POSIX appears to have an off-by-one error that isn't duplicated in
this change.

Previously, some of these functions would silently cap the size at
INT_MAX+1, and others would exit with an error after writing more
than INT_MAX characters.

PR: 39256
MFC after: 2 weeks


# 3c87aa1d 20-Nov-2011 David Chisnall <theraven@FreeBSD.org>

Implement xlocale APIs from Darwin, mainly for use by libc++. This adds a
load of _l suffixed versions of various standard library functions that use
the global locale, making them take an explicit locale parameter. Also
adds support for per-thread locales. This work was funded by the FreeBSD
Foundation.

Please test any code you have that uses the C standard locale functions!

Reviewed by: das (gdtoa changes)
Approved by: dim (mentor)


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 1b0181df 11-Mar-2010 John Baldwin <jhb@FreeBSD.org>

- Use an initializer macro to initialize fields in 'fake' FILE objects used
by *sprintf(), etc.
- Explicitly initialize _fl_mutex to PTHREAD_MUTEX_INITIALIZER for all FILE
objects. This is currently a nop on FreeBSD, but is import for other
platforms (or in the future) where PTHREAD_MUTEX_INITIALIZER is not simply
zero.

PR: threads/141198
Reported by: Jeremy Huddleston @ Apple
MFC after: 2 weeks


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 353ce11c 27-Feb-2009 David Schultz <das@FreeBSD.org>

Replace a dozen lines of code with a call to strnlen() / wcsnlen().


# 0881683b 27-Feb-2009 David Schultz <das@FreeBSD.org>

Make sure %zd treats negative arguments properly on 32-bit platforms.
Fix harmless but related bugs in %_$zd and %_$tu.

PR: 131880
MFC after: 1 week


# 21ca178e 22-Jan-2009 David Schultz <das@FreeBSD.org>

Add support for multibyte thousands_sep encodings, e.g., U+066C.
The integer thousands' separator code is rewritten in order to
avoid having to preallocate a buffer for the largest possible
digit string with the most possible instances of the longest
possible multibyte thousands' separator. The new version inserts
thousands' separators for integers using the same code as floating point.


# 5004a238 18-Jan-2009 David Schultz <das@FreeBSD.org>

Add support for multibyte decimal_point encodings, e.g., U+066B.


# a1805f7b 17-Jan-2009 David Schultz <das@FreeBSD.org>

When f[w]printf() is called on an unbuffered file like stdout, it
sets up a fake buffered FILE and then effectively calls itself
recursively. Unfortunately, gcc doesn't know how to do tail call
elimination in this case, and actually makes things worse by
inlining __sbprintf(). This means that f[w]printf() to stderr was
allocating about 5k of stack on 64-bit platforms, much of which was
never used.

I've reorganized things to eliminate the waste. In addition to saving
some stack space, this improves performance in my tests by anywhere
from 5% to 17% (depending on the test) when -fstack-protector is
enabled. I found no statistically significant performance difference
when stack protection is turned off. (The tests redirected stderr to
/dev/null.)


# 0a492640 14-Jan-2009 David Schultz <das@FreeBSD.org>

Reduce code duplication by moving functions that are identical in both
vfprintf.c and vfwprintf.c (except for char/wchar_t differences) to a
common header file.


# 814d1bc9 14-Jan-2009 David Schultz <das@FreeBSD.org>

Convert the insidious macros that handle printf()'s buffering into
slightly less evil inline functions, and move the buffering state into
a struct. This will make it possible for helper routines to produce
output for printf() directly, making it possible to untangle the code
somewhat.

In wprintf(), use the same buffering mechanism to reduce diffs to
printf(). This has the side-effect of causing wprintf() to catch write
errors that it previously ignored.


# e18701f4 10-Dec-2008 David Schultz <das@FreeBSD.org>

Consolidate some variable initializations. No substantive change.


# 33bff5d3 09-Dec-2008 David Schultz <das@FreeBSD.org>

Move the xprintf hook to where it belongs; it shouldn't be in the
middle of vfprintf's variable declarations.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# e62e5ff9 29-Jun-2008 David Schultz <das@FreeBSD.org>

Correctly handle malloc() failure. While here, reduce the code size a
bit by removing some calls to the inline function addtype().


# 2591efcc 29-Jun-2008 David Schultz <das@FreeBSD.org>

Reduce the level of duplication between vfprintf() and vfwprintf()
by moving the positional argument handling code to a new file,
printf-pos.c, and moving common definitions to printflocal.h.
No functional change intended.


# e5abb5e6 29-Jun-2008 David Schultz <das@FreeBSD.org>

Begin de-spaghettifying the code that handles positional arguments.
In particular, encapsulate the state of the type table in a struct,
and add inline functions to initialize, free, and manipulate that
state. This replaces some ugly macros that made proper error handling
impossible.

While here, remove an unneeded test for NULL and a variable that is
initialized (many times!) but never used. The compiler didn't catch
these because of rampant use of the same variable to mean different
things in different places.

This commit should not cause any changes in functionality.


# 1e98f887 17-Apr-2008 John Baldwin <jhb@FreeBSD.org>

Next stage of stdio cleanup: Retire __sFILEX and merge the fields back into
__sFILE. This was supposed to be done in 6.0. Some notes:
- Where possible I restored the various lines to their pre-__sFILEX state.
- Retire INITEXTRA() and just initialize the wchar bits (orientation and
mbstate) explicitly instead. The various places that used INITEXTRA
didn't need the locking fields or _up initialized. (Some places needed
_up to exist and not be off the end of a NULL or garbage pointer, but
they didn't require it to be initialized to a specific value.)
- For now, stdio.h "knows" that pthread_t is a 'struct pthread *' to
avoid namespace pollution of including all the pthread types in stdio.h.
Once we remove all the inlines and make __sFILE private it can go back
to using pthread_t, etc.
- This does not remove any of the inlines currently and does not change
any of the public ABI of 'FILE'.

MFC after: 1 month
Reviewed by: peter


# 970a466c 07-May-2007 David Schultz <das@FreeBSD.org>

We should never zero-pad INF or NaN (yielding silly strings like "00inf")
even if the programmer asks for zero padding.


# c879ae35 08-Jan-2007 Warner Losh <imp@FreeBSD.org>

Per Regents of the University of Calfornia letter, remove advertising
clause.

# If I've done so improperly on a file, please let me know.


# ac9913a7 02-Jan-2007 David Schultz <das@FreeBSD.org>

Fix rounding of 0xf for hex fp formats.

PR: 90333


# 500b77c7 21-Sep-2006 Alexander Kabaev <kan@FreeBSD.org>

Use correct type in va_arg argument.


# 75239a01 01-Apr-2006 Poul-Henning Kamp <phk@FreeBSD.org>

Add missing #if's for NO_FLOATING_POINT


# 75067f4f 16-Dec-2005 Poul-Henning Kamp <phk@FreeBSD.org>

Add an extensible version of our *printf(3) implementation to libc
on probationary terms: it may go away again if it transpires it is
a bad idea.

This extensible printf version will only be used if either
environment variable USE_XPRINTF is defined
or
one of the extension functions are called.
or
the global variable __use_xprintf is set greater than zero.

In all other cases our traditional printf implementation will
be used.

The extensible version is slower than the default printf, mostly
because less opportunity for combining I/O operation exists when
faced with extensions. The default printf on the other hand
is a bad case of spaghetti code.

The extension API has a GLIBC compatible part and a FreeBSD version
of same. The FreeBSD version exists because the GLIBC version may
run afoul of our FILE * locking in multithreaded programs and it
even further eliminate the opportunities for combining I/O operations.

Include three demo extensions which can be enabled if desired: time
(%T), hexdump (%H) and strvis (%V).

%T can format time_t (%T), struct timeval (%lT) and struct timespec (%llT)
in one of two human readable duration formats:
"%.3llT" -> "20349.245"
"%#.3llT" -> "5h39m9.245"

%H will hexdump a sequence of bytes and takes a pointer and a length
argument. The width specifies number of bytes per line.
"%4H" -> "65 72 20 65"
"%+4H" -> "0000 65 72 20 65"
"%#4H" -> "65 72 20 65 |er e|"
"%+#4H" -> "0000 65 72 20 65 |er e|"

%V will dump a string in strvis format.
"%V" -> "Hello\tWor\377ld" (C-style)
"%0V" -> "Hello\011Wor\377ld" (octal)
"%+V" -> "Hello%09Wor%FFld" (http-style)

Tests, comments, bugreports etc are most welcome.


# b384108e 13-Dec-2005 Poul-Henning Kamp <phk@FreeBSD.org>

/* You're not supposed to hit this problem */

For some denormalized long double values, a bug in __hldtoa() (called
from *printf()'s %A format) results in a base 16 digit being rounded
up from 0xf to 0x10.

When this digit is subsequently converted to string format, an index
of 10 reaches past the end of the uppper-case hex/char array, picking
up whatever the code segment happen to contain at that address.

This mostly seem to be some character from the upper half of the
byte range.

When using the %a format instead of %A, the first character past
the end of the lowercase hex/char table happens to be index 0 in
the uppercase hex/char table hextable and therefore the string
representation features a '0', which is supposedly correct.

This leads me to belive that the proper fix _may_ be as simple as
masking all but the lower four bits off after incrementing a hex-digit
in libc/gdtoa/_hdtoa.c:roundup(). I worry however that the upper
bit in 0x10 indicates a carry not carried.

Until das@ or bde@ finds time to visit this issue, extend the
hexdigit arrays with a 17th index containing '?' so that we get a
invalid but consistent and printable output in both %a and %A formats
whenever this bug strikes.

This unmasks the bug in the %a format therefore solving the real
issue may both become easier and more urgent.

Possibly related to: PR 85080
With help by: bde@


# d48c77b5 23-Jul-2005 Tim J. Robbins <tjr@FreeBSD.org>

Speed up __wcsconv() (and hence the printf() %ls format):
- use wcsrtombs() instead of a wcrtomb() loop where possible.
- avoid wcrtomb() loop when output precision is small.


# 1be5319a 16-Apr-2005 David Schultz <das@FreeBSD.org>

Be bug-for-bug compatible with the C standard with respect to
printf("%#.0o", 0). Cite an amusing passage from a defect report.


# 096ad104 26-Aug-2004 Dag-Erling Smørgrav <des@FreeBSD.org>

Don't forget to va_end() the va_list we get from va_copy().

Submitted by: Sean McNeil <sean@mcneil.com>
MFC after: 3 days


# cf6fc341 07-Jun-2004 Stefan Farfeleder <stefanf@FreeBSD.org>

The third operand of the conditional operator should have type void too.

Approved by: das (mentor)


# 52183d46 07-Jun-2004 David Schultz <das@FreeBSD.org>

Rename cantwrite() to prepwrite(). The latter is less confusing,
since the macro isn't really a predicate, and it has side-effects.


# 8de9e897 02-May-2004 David Schultz <das@FreeBSD.org>

- To make it easier to compile *printf() and *scanf() without
floating-point support, remove default definition of FLOATING_POINT
from the source, and change the compile-time option to
NO_FLOATING_POINT.
- Remove the HEXFLOAT option. It saves an insignificant amount of
space (<0.1% of the size of libc on i386) and complicates vfprintf()
and checkfmt().


# ccc8c6c3 22-Apr-2004 Tim J. Robbins <tjr@FreeBSD.org>

Use the correct size to allocate, copy and clear argument type tables
after their change from an array of char to an array of enum.
This fixes problems that occurred when using positional arguments in
format strings, particularly with more than STATIC_ARG_TBL_SIZE (8)
of them.

PR: 65841
Submitted by: Steven Smith (mostly)


# 93996f6d 07-Apr-2004 Tim J. Robbins <tjr@FreeBSD.org>

Prepare to handle trivial state-dependent encodings. Full support for
state-dependent encodings with locking shifts will come later if there
is demand for it.


# 8f592773 18-Jan-2004 David Schultz <das@FreeBSD.org>

Implement __hdtoa() and __hldtoa() and enable printf() support for %a
and %A, which print floating-point numbers in hexadecimal.


# 904322a5 18-Jan-2004 David Schultz <das@FreeBSD.org>

Fix some bugs affecting the %a and %A format specifiers. Since
these are not fully implemented and ifdef'd out, the bugs have
never manifested themselves. Specifically:

- Fix a memory leak in the case where %a follows another
floating-point format.
- Make the %a/%A code behave like %e/%E with respect to
precision.
- It is no longer valid to assume that '-' and '0x' are
mutually exclusive.
- Address other minor issues.


# 2a49d376 05-Nov-2003 Tim J. Robbins <tjr@FreeBSD.org>

Pass NULL instead of a pointer to a zeroed mbstate_t object.


# 1f2a0cdf 19-Apr-2003 David Schultz <das@FreeBSD.org>

%E-like %g and %G conversions should remove trailing zeroes unless
the # flag is present. Implement this behavior and add a comment
describing it.

Noticed by: Enache Adrian <enache@rdslink.ro>
Pointy hat to: das


# 81ae2e9a 14-Apr-2003 David Schultz <das@FreeBSD.org>

Fix a bug where printf was erroneously printing a decimal point for
%f and sufficiently short %g specifiers where the precision was
explicitly zero, no '#' flag was specified, and the floating point
argument was > 0 and <= 0.5. While at it, add some comments to better
explain the relevant bits of code.

Noticed by: Christoph Kukulies <kuku@physik.rwth-aachen.de>


# 6f098a48 06-Apr-2003 Andrey A. Chernov <ache@FreeBSD.org>

__wcsconv(): free(convbuf) before returning NULL


# d890afb8 06-Apr-2003 David Schultz <das@FreeBSD.org>

Today just isn't my day. Remove some old commented out code that snuck
into the last commit.

Noticed by: mike


# 3b204b7d 06-Apr-2003 David Schultz <das@FreeBSD.org>

- %e conversions with precision 0 should not cause a decimal point to
be printed.
- Fix %f conversions where the number of significant digits is < expt.
This would be a one-line change were it not for thousands separators.
Noticed by tjr.
- Remove some unnecessary code in the parsing of precision specifiers.


# ebbad5ec 05-Apr-2003 David Schultz <das@FreeBSD.org>

Rework the floating point code in printf(). Significant changes:

- We used to round long double arguments to double. Now we print
them properly.

- Bugs involving '%F', corner cases of '#' and 'g' format
specifiers, and the '.*' precision specifier have been
fixed.

- Added support for the "'" specifier to print thousands' grouping
characters in a locale-dependent manner.

- Implement the __vfprintf() side of hexadecimal floating point
support. All that is still needed is a routine to convert the
mantissa to hex digits one nibble at a time in the style of ultoa().

Reviewed by: silence on standards@


# 38cac8f8 05-Apr-2003 David Schultz <das@FreeBSD.org>

Correct some buffer sizes.

- __vfprintf()'s 'buf' has never been used for floating point, so
don't define it in terms of (incorrect) constants describing
floating point numbers. The actual size needed depends on
sizeof(uintmax_t) and locale details, so I slightly overestimated.

- We don't need a 308-character buffer to store the string "308".
With long doubles and %a we need more than three characters, though.


# 3ba6b6dd 13-Mar-2003 David Schultz <das@FreeBSD.org>

Kludge around a bug that results from printf() assuming that
dtoa() is buggy. The bug would cause incorrect output to be
generated when format strings such as '%5.0f' were used with
nonzero numbers whose magnitude is less than 1.

Reported by: df(1) by way of periodic(8)
Reviewed by: mike


# 6a66acb5 12-Mar-2003 David Schultz <das@FreeBSD.org>

Replace our ancient dtoa/strtod implementation with the gdtoa
package, a more recent, generalized set of routines. Among the
changes:
- Declare strtof() and strtold() in stdlib.h.
- Add glue to libc to support these routines for all kinds
of ``long double''.
- Update printf() to reflect the fact that dtoa works slightly
differently now.

As soon as I see that nothing has blown up, I will kill
src/lib/libc/stdlib/strtod.c. Soon printf() will be able
to use the new routines to output long doubles without loss
of precision, but numerous bugs in the existing code must
be addressed first.

Reviewed by: bde (briefly), mike (mentor), obrien


# 6180233f 15-Oct-2002 Tim J. Robbins <tjr@FreeBSD.org>

Set the error bit on the stream if an encoding error occurs. Improve
handling of multibyte sequences representing null wide characters.


# 927ecbf3 15-Oct-2002 Tim J. Robbins <tjr@FreeBSD.org>

Add support for the XSI %C and %S formats, which are the same as %lc
and %ls.


# d07090a8 23-Sep-2002 Tim J. Robbins <tjr@FreeBSD.org>

Use the new va_copy macro to copy variable argument lists instead of
assignment. This is needed on powerpc but is also more correct for the
other ports.

Submitted by: grehan
Tested on: alpha, i386, sparc64


# b9aac308 18-Sep-2002 Tim J. Robbins <tjr@FreeBSD.org>

Implement the %ls and %lc conversions for printing wide character strings
and wide characters. These were already documented in the manual page,
with an entry mentioning that they were not implemented yet. The XSI
%S and %C synoyms have not been added.


# 4d783ded 15-Sep-2002 Tim J. Robbins <tjr@FreeBSD.org>

Convert eight space indents to tabs in the "*" format handling code.


# 58d38e25 06-Sep-2002 Tim J. Robbins <tjr@FreeBSD.org>

Style: One space between "restrict" qualifier and "*".


# 3dd65760 27-Aug-2002 Jens Schweikhardt <schweikh@FreeBSD.org>

Print a '-' sign for negative zero. Tested with

#include <stdio.h>
int main(void)
{
printf("%+f\n", -0.0);
printf("%+f\n", +0.0);
printf("%+f\n", 0.0);
return 0;
}

to output
-0.000000
+0.000000
+0.000000

PR: bin/41823
Submitted by: GOTO Kentaro <gotoken@notwork.org>
Liked by: bde
MFC after: 3 weeks


# f8418db7 15-Aug-2002 Robert Drehmel <robert@FreeBSD.org>

- For compliance with IEEE Std 1003.1-2001, add the 'restrict'
qualifier to function prototypes and definitions where
appropriate using the '__restrict' macro.
- Update the manual page.


# e74101e4 13-Aug-2002 Tim J. Robbins <tjr@FreeBSD.org>

Basic support for wide character I/O: getwc(), fgetwc(), getwchar(),
putwc(), fputwc(), putwchar(), ungetwc(), fwide().


# a82bbc73 28-May-2002 Alfred Perlstein <alfred@FreeBSD.org>

Assume __STDC__, remove non-__STDC__ code.

Submitted by: keramida


# 333fc21e 22-Mar-2002 David E. O'Brien <obrien@FreeBSD.org>

Fix the style of the SCM ID's.
I believe have made all of libc .c's as consistent as possible.


# 1372519b 22-Mar-2002 David E. O'Brien <obrien@FreeBSD.org>

Remove multi-line __P() usage.


# c05ac53b 21-Mar-2002 David E. O'Brien <obrien@FreeBSD.org>

Remove __P() usage.


# 8fb3f3f6 21-Mar-2002 David E. O'Brien <obrien@FreeBSD.org>

Remove 'register' keyword.


# 2e394b2f 17-Dec-2001 Alexey Zelkin <phantom@FreeBSD.org>

Fix some style bugs

Prompted by: mike


# 243e90d6 13-Dec-2001 Alexey Zelkin <phantom@FreeBSD.org>

Also fix cases when thousands separator should be put before number. For
example before for grouping sequence "\003\003" number 123456 was formated
as ",123,456", now "123,456".


# 98ee7635 13-Dec-2001 Alexey Zelkin <phantom@FreeBSD.org>

Respect locale while handling of \' flag.

In original version grouping was hardcoded. It assumed that thousands
separator should be inserted to separate each 3 numbers. I.e. grouping
string "\003" was assumed for all cases. In correct case (per POSIX)
vfprintf should respect locale defined non-monetary (LC_NUMERIC
category) grouping sequence.

Also simplify thousands_sep handling.


# 7ae5c679 06-Dec-2001 Alexey Zelkin <phantom@FreeBSD.org>

* localeconv() usage is not FLOATING_POINT specific anymore (due to "'" flag
addition) so move locale.h inclusion out of FLOATING_POINT ifdef's.
* add more comments


# 7735bb0f 29-Nov-2001 Bill Fenner <fenner@FreeBSD.org>

Implement several of the c99 updates to printf(3):
- New length modifiers: hh, j, t, z.
- New flag: '. Note that %'f is not yet implemented.
- Use "inf"/"nan" for efg formats, "INF"/"NAN" for EFG formats.
- Implemented %q in terms of %ll; if "quad_t" is not "long long"
%q will break.

Still to do:
- %C, %S, %lc, %ls (wide character support)
- %'f (thousands in integer portion of %f)
- %a/%A (exact hex representation of floating-point numbers)

Garrett Wollman wrote the first version of the vfprintf.c update;
Mike Barcroft wrote the first version of the printf.3 changes.


# 18ca70d1 14-Oct-2001 Bruce Evans <bde@FreeBSD.org>

Fixed style bugs in previous commit.


# a387081c 14-Oct-2001 Doug Rabson <dfr@FreeBSD.org>

Make this compile on ia64.


# 6dac8ac9 19-Aug-2001 Kris Kennaway <kris@FreeBSD.org>

Mark some functions as __printflike() and/or taking const char * arguments
instead of char *.

MFC after: 2 weeks


# 2ffc61ba 15-Feb-2001 Tor Egge <tegge@FreeBSD.org>

Remove freelists managed by Balloc/Bfree.
Change __dtoa to not free the string it allocated the previous time it was
called. The caller now frees the string after usage if appropiate.

PR: 15070
Reviewed by: deischen


# 9ad80ab5 09-Feb-2001 Andrey A. Chernov <ache@FreeBSD.org>

Take decimal point from locale instead of hardcoded '.' (SUSv2)


# d7e56cc9 09-Feb-2001 Tor Egge <tegge@FreeBSD.org>

Backout previous commit. Use of spinlocks was not approved.
PR: 15070


# 1d538861 08-Feb-2001 Tor Egge <tegge@FreeBSD.org>

Protect freelists managed by Balloc/Bfree with a spinlock.
Change __dtoa to not free the string it allocated the previous time it was
called. The caller now frees the string after usage if appropiate.

PR: 15070


# d201fe46 24-Jan-2001 Daniel Eischen <deischen@FreeBSD.org>

Remove _THREAD_SAFE and make libc thread-safe by default by
adding (weak definitions to) stubs for some of the pthread
functions. If the threads library is linked in, the real
pthread functions will pulled in.

Use the following convention for system calls wrapped by the
threads library:
__sys_foo - actual system call
_foo - weak definition to __sys_foo
foo - weak definition to __sys_foo

Change all libc uses of system calls wrapped by the threads
library from foo to _foo. In order to define the prototypes
for _foo(), we introduce namespace.h and un-namespace.h
(suggested by bde). All files that need to reference these
system calls, should include namespace.h before any standard
includes, then include un-namespace.h after the standard
includes and before any local includes. <db.h> is an exception
and shouldn't be included in between namespace.h and
un-namespace.h namespace.h will define foo to _foo, and
un-namespace.h will undefine foo.

Try to eliminate some of the recursive calls to MT-safe
functions in libc/stdio in preparation for adding a mutex
to FILE. We have recursive mutexes, but would like to avoid
using them if possible.

Remove uneeded includes of <errno.h> from a few files.

Add $FreeBSD$ to a few files in order to pass commitprep.

Approved by: -arch


# 42cebaa5 06-Jan-2001 Archie Cobbs <archie@FreeBSD.org>

Fix bugs in the handling of > 8 positional arguments:
- The stack was getting smashed by __grow_type_table()
- reallocf() was being called with the wrong pointer
- The maximum argument number was being incorrectly computed

PR: misc/23521


# 7f3dea24 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 93263596 11-Mar-1999 Doug Rabson <dfr@FreeBSD.org>

Add support for long long modifier (e.g. %llx, %lld).

Reviewed by: bde


# e8420087 15-Sep-1998 Warner Losh <imp@FreeBSD.org>

Replace memory leaking instances of realloc with non-leaking reallocf.
In some cases replace if (a == null) a = malloc(x); else a =
realloc(a, x); with simple reallocf(a, x). Per ANSI-C, this is
guaranteed to be the same thing.

I've been running these on my system here w/o ill effects for some
time. However, the CTM-express is at part 6 of 34 for the CAM
changes, so I've not been able to do a build world with the CAM in the
tree with these changes. Shouldn't impact anything, but...


# 77af5d1a 07-May-1998 John Birrell <jb@FreeBSD.org>

Don't assign the va_list variable 'ap' directly to the argtable because
va_list is not a pointer on alpha. Instead, use the va_arg() macro
to return the address that is stored in the argtable.


# ec216c26 11-Apr-1998 John Birrell <jb@FreeBSD.org>

Add FILE locking stubs for libc.

Change the FILE locking to support kernel threads when linked with
libpthread (which you haven't see yet). This requires that libc become
thread-safe and thread-aware, testing __isthreaded before attempting
to do lock/unlock calls. The impact on non-threaded programs is minor.
This change works with libc_r, so it's the best compromise.


# b250f248 04-Jan-1998 Andrey A. Chernov <ache@FreeBSD.org>

size_t -> unsigned
in arguments length INT_MAX overflow check
Suggested-by: bde


# 92e88f87 24-Dec-1997 Andrey A. Chernov <ache@FreeBSD.org>

Add overflow checks: if output size becomes bigger than INT_MAX,
just return EOF


# 6e690ad4 24-Dec-1997 Andrey A. Chernov <ache@FreeBSD.org>

Return back to BSD snprintf semantics which recent C9x standard adopts
instead of Singe Unix, thanx Bruce for explaining, I am not realize
standards war was there.

But now, fix n == 0 case to not return error and fix check for too
big n.

Things left to do: check for overflow in arguments.


# 97adcd5b 24-Dec-1997 Andrey A. Chernov <ache@FreeBSD.org>

Fix snprintf(...%n...)
to pass not more than buffer size to %n agrument, old variant
always assume infinite buffer.
%n is for actually transmitted characters, not for planned ones.


# 6a93659f 19-Dec-1997 Bruce Evans <bde@FreeBSD.org>

Comment that long double is poorly implemented, not that it is unimplemented.


# 7e546392 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Revert $FreeBSD$ to $Id$


# efb7e53d 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

The following patch to lib/libc/stdio implements positional arguments in
a manner consistent with other implementations. Its done in a way that
adds only a tiny amount of overhead when positional arguments are not used.
I also have a test program to go with this, but don't know where it belongs
in the tree.

Submitted-By: Bill Fenner <fenner@FreeBSD.ORG>


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# ce51cf03 22-Jun-1996 James Raynard <jraynard@FreeBSD.org>

Suggested by: Bruce Evans, Jeffrey Hsu, Gary Palmer

Added $Id$'s to files that were lacking them (gpalmer), made some
cosmetic changes to conform to style guidelines (bde) and checked
against NetBSD and Lite2 to remove unnecessary divergences (hsu, bde)

One last code cleanup:-

Removed spurious casts in fseek.c and stdio.c.
Added missing function argument in fwalk.c.
Added missing header include in flags.c and rget.c.
Put in casts where int's were being passed as size_t's.
Put in missing prototypes for static functions.
Changed second args of __sflags() inflags.c and writehook() in vasprintf.c
from char * to const char * to conform to prototypes.

This directory now compiles with no warnings with -Wall under
gcc-2.6.3 and with considerably less warnings than before with the
ultra-pedantic script I used for testing. (Most of the remaining ones
are due to const poisoning).


# 261a532a 20-Mar-1996 Bill Fenner <fenner@FreeBSD.org>

The 4.4-lite vfprintf counted the %# hex prefix and the sign in
the precision; ANSI X3J11 is not crystal clear but certainly says
that the precision specifies the number of /digits/, and signs
and "0x" aren't really digits.

NetBSD already has a similar patch.


# f70177e7 21-Jan-1996 Julian Elischer <julian@FreeBSD.org>

Reviewed by: julian and (hsu?)
Submitted by: John Birrel(L?)

changes for threadsafe operations


# 6c06b4e2 29-May-1995 Rodney W. Grimes <rgrimes@FreeBSD.org>

Remove trailing whitespace.


# ffe57f1a 06-Apr-1995 Bruce Evans <bde@FreeBSD.org>

Obtained from: 1.1.5 (originally by jtc)

Fix printf("%g", 0.0) - print "0", not "0.". The previous fixes in this
area had one non-cosmetic (non-)change that caused this bug.

Bruce


# 918bed75 12-Mar-1995 Bruce Evans <bde@FreeBSD.org>

Remove `|| flags & ALT == 0' which was an obscure no-op, not a
parenthesization/precedence bug.


# d26be6f0 12-Mar-1995 Bruce Evans <bde@FreeBSD.org>

Obtained from: 1.1.5. Originally by jtc. Cosmetically changed for this
commit by bde.

Fix bugs in floating point formatting. The 4.4lite version is similar
to revision 1.3 in old-cvs and is missing all of jtc's fixes in revision
1.4 in old-cvs. Revision 1.2 in ncvs fixed one of the old bugs but
introduced at least one new one (for %.0e).

old-cvs log:
revision 1.4
date: 1993/11/04 19:38:22; author: jtc; state: Exp; lines: +33 -20
My work from NetBSD to make printf() & friends ANSI C compliant.
Fixes several bugs in floating point formatting:
1. Trailing zeros were being stripped with %e format.
2. %g/%G formats incorrect.
3. Lots of other nits.


# 2cc220b6 18-Jan-1995 Doug Rabson <dfr@FreeBSD.org>

Fix handling of 'e' format floating point so that it prints trailing zeros
correctly.


# 58f0484f 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite Lib Sources