summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/vfprintf.c
Commit message (Collapse)AuthorAgeFilesLines
* We should never zero-pad INF or NaN (yielding silly strings like "00inf")das2007-05-081-0/+1
| | | | even if the programmer asks for zero padding.
* Per Regents of the University of Calfornia letter, remove advertisingimp2007-01-091-4/+0
| | | | | | clause. # If I've done so improperly on a file, please let me know.
* Fix rounding of 0xf for hex fp formats.das2007-01-031-2/+2
| | | | PR: 90333
* Use correct type in va_arg argument.kan2006-09-211-1/+1
|
* Add missing #if's for NO_FLOATING_POINTphk2006-04-011-2/+4
|
* Add an extensible version of our *printf(3) implementation to libcphk2005-12-161-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* /* You're not supposed to hit this problem */phk2005-12-131-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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@
* Speed up __wcsconv() (and hence the printf() %ls format):tjr2005-07-241-34/+30
| | | | | - use wcsrtombs() instead of a wcrtomb() loop where possible. - avoid wcrtomb() loop when output precision is small.
* Be bug-for-bug compatible with the C standard with respect todas2005-04-161-2/+8
| | | | printf("%#.0o", 0). Cite an amusing passage from a defect report.
* Don't forget to va_end() the va_list we get from va_copy().des2004-08-261-0/+1
| | | | | Submitted by: Sean McNeil <sean@mcneil.com> MFC after: 3 days
* The third operand of the conditional operator should have type void too.stefanf2004-06-081-1/+1
| | | | Approved by: das (mentor)
* Rename cantwrite() to prepwrite(). The latter is less confusing,das2004-06-081-1/+1
| | | | since the macro isn't really a predicate, and it has side-effects.
* - To make it easier to compile *printf() and *scanf() withoutdas2004-05-021-24/+16
| | | | | | | | | 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().
* Use the correct size to allocate, copy and clear argument type tablestjr2004-04-221-6/+9
| | | | | | | | | | 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)
* Prepare to handle trivial state-dependent encodings. Full support fortjr2004-04-071-4/+12
| | | | | state-dependent encodings with locking shifts will come later if there is demand for it.
* Implement __hdtoa() and __hldtoa() and enable printf() support for %adas2004-01-181-5/+2
| | | | and %A, which print floating-point numbers in hexadecimal.
* Fix some bugs affecting the %a and %A format specifiers. Sincedas2004-01-181-6/+16
| | | | | | | | | | | | | 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.
* Pass NULL instead of a pointer to a zeroed mbstate_t object.tjr2003-11-051-9/+4
|
* %E-like %g and %G conversions should remove trailing zeroes unlessdas2003-04-191-0/+7
| | | | | | | | the # flag is present. Implement this behavior and add a comment describing it. Noticed by: Enache Adrian <enache@rdslink.ro> Pointy hat to: das
* Fix a bug where printf was erroneously printing a decimal point fordas2003-04-141-8/+10
| | | | | | | | | %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>
* __wcsconv(): free(convbuf) before returning NULLache2003-04-071-2/+4
|
* Today just isn't my day. Remove some old commented out code that snuckdas2003-04-071-1/+1
| | | | | | into the last commit. Noticed by: mike
* - %e conversions with precision 0 should not cause a decimal point todas2003-04-071-18/+22
| | | | | | | | 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.
* Rework the floating point code in printf(). Significant changes:das2003-04-051-151/+189
| | | | | | | | | | | | | | | | | | - 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@
* Correct some buffer sizes.das2003-04-051-10/+16
| | | | | | | | | | - __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.
* Kludge around a bug that results from printf() assuming thatdas2003-03-141-1/+1
| | | | | | | | | 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
* Replace our ancient dtoa/strtod implementation with the gdtoadas2003-03-121-9/+10
| | | | | | | | | | | | | | | | | | 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
* Set the error bit on the stream if an encoding error occurs. Improvetjr2002-10-161-2/+6
| | | | handling of multibyte sequences representing null wide characters.
* Add support for the XSI %C and %S formats, which are the same as %lctjr2002-10-161-0/+12
| | | | and %ls.
* Use the new va_copy macro to copy variable argument lists instead oftjr2002-09-241-1/+1
| | | | | | | | assignment. This is needed on powerpc but is also more correct for the other ports. Submitted by: grehan Tested on: alpha, i386, sparc64
* Implement the %ls and %lc conversions for printing wide character stringstjr2002-09-191-6/+110
| | | | | | 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.
* Convert eight space indents to tabs in the "*" format handling code.tjr2002-09-161-43/+43
|
* Style: One space between "restrict" qualifier and "*".tjr2002-09-061-1/+1
|
* Print a '-' sign for negative zero. Tested withschweikh2002-08-271-7/+2
| | | | | | | | | | | | | | | | | | | | | #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
* - For compliance with IEEE Std 1003.1-2001, add the 'restrict'robert2002-08-151-1/+2
| | | | | | qualifier to function prototypes and definitions where appropriate using the '__restrict' macro. - Update the manual page.
* Basic support for wide character I/O: getwc(), fgetwc(), getwchar(),tjr2002-08-131-0/+1
| | | | putwc(), fputwc(), putwchar(), ungetwc(), fwide().
* Assume __STDC__, remove non-__STDC__ code.alfred2002-05-281-4/+0
| | | | Submitted by: keramida
* Fix the style of the SCM ID's.obrien2002-03-221-4/+2
| | | | I believe have made all of libc .c's as consistent as possible.
* Remove multi-line __P() usage.obrien2002-03-221-5/+5
|
* Remove __P() usage.obrien2002-03-211-6/+6
|
* Remove 'register' keyword.obrien2002-03-211-2/+2
|
* Fix some style bugsphantom2001-12-171-15/+18
| | | | Prompted by: mike
* Also fix cases when thousands separator should be put before number. Forphantom2001-12-131-2/+4
| | | | | example before for grouping sequence "\003\003" number 123456 was formated as ",123,456", now "123,456".
* Respect locale while handling of \' flag.phantom2001-12-131-22/+63
| | | | | | | | | | 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.
* * localeconv() usage is not FLOATING_POINT specific anymore (due to "'" flagphantom2001-12-071-3/+3
| | | | | addition) so move locale.h inclusion out of FLOATING_POINT ifdef's. * add more comments
* Implement several of the c99 updates to printf(3):fenner2001-11-301-115/+233
| | | | | | | | | | | | | | | | - 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.
* Fixed style bugs in previous commit.bde2001-10-151-15/+15
|
* Make this compile on ia64.dfr2001-10-141-25/+46
|
* Mark some functions as __printflike() and/or taking const char * argumentskris2001-08-201-1/+1
| | | | | | instead of char *. MFC after: 2 weeks
* Remove freelists managed by Balloc/Bfree.tegge2001-02-151-5/+18
| | | | | | | | 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
OpenPOWER on IntegriCloud