summaryrefslogtreecommitdiff
path: root/lib/libc/stdio
Commit message (Collapse)AuthorAgeFilesLines
* MFC 205021:John Baldwin2010-10-1212-39/+22
| | | | | | | | | | | | - 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. Notes: svn path=/stable/8/; revision=213720
* MFC r203958: %U was macroized in mdoc(7), escape.Ruslan Ermilov2010-10-061-1/+1
| | | | Notes: svn path=/stable/8/; revision=213473
* MFH r200600: Clarify what's meant by NUL for getline.3Ulrich Spörlein2010-06-191-1/+2
| | | | | | | | PR: docs/141125 Submitted by: Jeremy Huddleston <jeremyhu@apple.com> Notes: svn path=/stable/8/; revision=209349
* MFC r204447:Jaakko Heinonen2010-03-121-0/+4
| | | | | | | | | | | In _gettemp(), check that the length of the path doesn't exceed MAXPATHLEN. Otherwise the path name (or part of it) may not fit to carrybuf causing a buffer overflow. PR: bin/140228 Notes: svn path=/stable/8/; revision=205070
* MFC r197752:David Schultz2010-01-241-2/+2
| | | | | | | | | | | | | | | Better glibc compatibility for getline/getdelim: - Tolerate applications that pass a NULL pointer for the buffer and claim that the capacity of the buffer is nonzero. - If an application passes in a non-NULL buffer pointer and claims the buffer has zero capacity, we should free (well, realloc) it anyway. It could have been obtained from malloc(0), so failing to free it would be a small memory leak. Notes: svn path=/stable/8/; revision=202947
* MFC r200802:Xin LI2010-01-201-9/+1
| | | | | | | | | | Use vsprintf instead of rolling our own. PR: bin/140496 Submitted by: Jeremy Huddleston <jeremyhu apple.com> Notes: svn path=/stable/8/; revision=202666
* MFC r200800:Xin LI2010-01-201-24/+1
| | | | | | | | | | Use vsscanf instead of rolling our own. PR: bin/140530 Submitted by: Jeremy Huddleston <jeremyhu apple.com> Notes: svn path=/stable/8/; revision=202665
* MFC r200799:Xin LI2010-01-201-8/+3
| | | | | | | K&R -> ANSI prototype. Notes: svn path=/stable/8/; revision=202664
* MFC: r201836Christian Brueffer2010-01-151-3/+2
| | | | | | | Remove unnecessary quoting and markup, add missing punctuation. Notes: svn path=/stable/8/; revision=202413
* MFC: r200019Christian Brueffer2009-12-071-2/+2
| | | | | | | Fix the dprintf() prototype. Notes: svn path=/stable/8/; revision=200211
* MFC revs 199781,199782,199784,199785,199786:Garrett Wollman2009-12-023-3/+3
| | | | | | | | | | | | | | | | | | | | Eliminate dead stores. In __mbsconv(), if prec was zero, nconv could have been used uninitialized. Initialize it to a safe value so that there's no chance of returning an error if stack garbage happens to be equal to (size_t)-1 or (size_t)-2. In svc_raw_reply(), don't leave stat uninitialized if the MSG_ACCEPTED && SUCCESS case succeeds. The stack garbage might be zero. In clnt_raw_create(), avoid minor race condition initializing the file-scope variable clntraw_private. Found by: Clang static analyzer Notes: svn path=/stable/8/; revision=200016
* Fix fwrite() to return 0 when size or nmemb are zero.Ed Schouten2009-07-122-4/+9
| | | | | | | | | | | Right now nmemb is returned when size is 0. In newer versions of the standards, it is explicitly required that fwrite() should return 0. Submitted by: Christoph Mallon Approved by: re (kib) Notes: svn path=/head/; revision=195637
* Return -1 instead of 0 upon reaching EOF. This is somewhat ill-advisedDavid Schultz2009-04-062-4/+6
| | | | | | | | | | | because it means getdelim() returns -1 for both error and EOF, and never returns 0. However, this is what the original GNU implementation does, and POSIX inherited the bug. Reported by: marcus@ Notes: svn path=/head/; revision=190773
* Add dprintf() and vdprintf() from POSIX.1-2008. Like getline(),David Schultz2009-03-046-32/+198
| | | | | | | | | dprintf() is a simple wrapper around another function, so we may as well implement it. But also like getline(), we can't prototype it by default right now because it would break too many ports. Notes: svn path=/head/; revision=189356
* Rewrite asprintf() as a wrapper around vasprintf(), thus reducing theDavid Schultz2009-03-021-43/+22
| | | | | | | | number of functions that have an incestuous relationship with the arcane innards of stdio. Notes: svn path=/head/; revision=189271
* The argument corresponding to %zn is supposed to be an ssize_t *, notDavid Schultz2009-03-022-6/+6
| | | | | | | a size_t *, although the distinction is moot in practice. Notes: svn path=/head/; revision=189268
* Use C99-style initializers. No functional change.David Schultz2009-03-011-4/+9
| | | | | | | Reviewed by: md5(1) Notes: svn path=/head/; revision=189249
* Replace a dozen lines of code with a call to strnlen() / wcsnlen().David Schultz2009-02-282-33/+2
| | | | Notes: svn path=/head/; revision=189138
* - Add getdelim(), getline(), stpncpy(), strnlen(), wcsnlen(),David Schultz2009-02-288-5/+377
| | | | | | | | | | | | | | | wcscasecmp(), and wcsncasecmp(). - Make some previously non-standard extensions visible if POSIX_VISIBLE >= 200809. - Use restrict qualifiers in stpcpy(). - Declare off_t and size_t in stdio.h. - Bump __FreeBSD_version in case the new symbols (particularly getline()) cause issues with ports. Reviewed by: standards@ Notes: svn path=/head/; revision=189136
* Make sure %zd treats negative arguments properly on 32-bit platforms.David Schultz2009-02-283-5/+8
| | | | | | | | | | Fix harmless but related bugs in %_$zd and %_$tu. PR: 131880 MFC after: 1 week Notes: svn path=/head/; revision=189131
* Better wording for clearing EOF indicator.Tom Rhodes2009-01-281-0/+4
| | | | | | | Submitted by: keramida and jhb Notes: svn path=/head/; revision=187823
* Remove another comment about clearing EOF indicator.Tom Rhodes2009-01-281-4/+1
| | | | | | | Noticed by: bde Notes: svn path=/head/; revision=187817
* Update the manpage to reflect r145172.David Schultz2009-01-281-2/+1
| | | | Notes: svn path=/head/; revision=187809
* Remove comment about clearerr() being the only method of clearingTom Rhodes2009-01-281-3/+1
| | | | | | | | | | | | the EOF indicator, fseek() may also be used for this. Bump document date. PR: 76333 Submitted by: Yoshihiko Sarumaru <mistral@imasy.or.jp> Notes: svn path=/head/; revision=187805
* Add support for multibyte thousands_sep encodings, e.g., U+066C.David Schultz2009-01-223-173/+225
| | | | | | | | | | | 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. Notes: svn path=/head/; revision=187582
* - Add support for multibyte decimal_point encodings, e.g., U+066B.David Schultz2009-01-192-23/+49
| | | | | | | | A forthcoming gdtoa import is needed to make this fully work. - Improve the way "nan(...)" is parsed. Notes: svn path=/head/; revision=187422
* Add support for multibyte decimal_point encodings, e.g., U+066B.David Schultz2009-01-192-23/+35
| | | | Notes: svn path=/head/; revision=187421
* When f[w]printf() is called on an unbuffered file like stdout, itDavid Schultz2009-01-172-14/+23
| | | | | | | | | | | | | | | | | | | 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.) Notes: svn path=/head/; revision=187369
* Simplify printf's inlined output buffering routines. On amd64, thisDavid Schultz2009-01-171-18/+18
| | | | | | | reduces the code size by about 10% and improves performance slightly. Notes: svn path=/head/; revision=187354
* Introduce a local variable and use it instead of passed in parameterRoman Divacky2009-01-152-2/+6
| | | | | | | | | | | to get rid of restrict qualifier discarding. This lets libc compile cleanly in gnu99 mode. Suggested by: kib, christoph.mallon at gmx.de Approved by: kib (mentor) Notes: svn path=/head/; revision=187302
* Reduce code duplication by moving functions that are identical in bothDavid Schultz2009-01-153-427/+216
| | | | | | | | vfprintf.c and vfwprintf.c (except for char/wchar_t differences) to a common header file. Notes: svn path=/head/; revision=187284
* Convert the insidious macros that handle printf()'s buffering intoDavid Schultz2009-01-153-86/+204
| | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=187277
* Set the error indicator on an attempt to write to a read-only stream.David Schultz2009-01-081-0/+1
| | | | | | | | PR: 127335 MFC after: 2 weeks Notes: svn path=/head/; revision=186887
* Consolidate some variable initializations. No substantive change.David Schultz2008-12-112-13/+13
| | | | Notes: svn path=/head/; revision=185904
* Move the xprintf hook to where it belongs; it shouldn't be in theDavid Schultz2008-12-101-6/+4
| | | | | | | middle of vfprintf's variable declarations. Notes: svn path=/head/; revision=185825
* Fix fread() to return a correct value on platforms where sizeof(int) !=Ruslan Ermilov2008-12-011-1/+1
| | | | | | | | | | sizeof(size_t), i.e. on all 64-bit platforms. Reported by: Andrey V. Elsukov MFC after: 3 days Notes: svn path=/head/; revision=185516
* Initialize "nconv" to a reasonable value in all code paths. Prior toColin Percival2008-08-041-1/+3
| | | | | | | | | | this commit, sprintf("%s", "") could fail depending on what happened to be on the stack. Found by: LLVM/Clang Static Checker Notes: svn path=/head/; revision=181281
* Fix a few bugs with the _gettemp() routine which implements mkstemp(),John Baldwin2008-07-281-11/+26
| | | | | | | | | | | | | | | | | | mkstemps(), and mkdtemp(). - Add proper range checking for the 'slen' parameter passed to mkstemps(). - Try all possible permutations of a template if a collision is encountered. Previously, once a single template character reached 'z', it would not wrap around to '0' and keep going until it encountered the original starting letter. In the edge case that the randomly generated starting name used all 'z' characters, only that single name would be tried before giving up. PR: standards/66531 Submitted by: Jim Luther Obtained from: Apple MFC after: 1 week Notes: svn path=/head/; revision=180938
* Use arc4random_uniform(3) since modulo size is not power of 2Andrey A. Chernov2008-07-221-1/+1
| | | | Notes: svn path=/head/; revision=180696
* Fix a bogon in the previous commit and add some missing error checks.David Schultz2008-06-291-9/+12
| | | | Notes: svn path=/head/; revision=180107
* Correctly handle malloc() failure. While here, reduce the code size aDavid Schultz2008-06-294-103/+162
| | | | | | | bit by removing some calls to the inline function addtype(). Notes: svn path=/head/; revision=180106
* Factor out the code that builds the argument table. We don't need separateDavid Schultz2008-06-291-130/+47
| | | | | | | | | normal and wide character versions of it. No functional change. Notes: svn path=/head/; revision=180105
* Reduce the level of duplication between vfprintf() and vfwprintf()David Schultz2008-06-295-975/+888
| | | | | | | | | 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. Notes: svn path=/head/; revision=180104
* Begin de-spaghettifying the code that handles positional arguments.David Schultz2008-06-292-188/+306
| | | | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=180102
* Remove useless call to getdtablesize(2) in fdopen(3) and its uselessAntoine Brodin2008-05-101-4/+0
| | | | | | | | | | | | variable nofile. PR: 123109 Submitted by: Christoph Mallon Approved by: rwatson (mentor) MFC after: 1 month Notes: svn path=/head/; revision=178921
* Retire the __fgetcookie(), __fgetpendout(), and __fsetfileno() accessorsJohn Baldwin2008-05-052-27/+0
| | | | | | | as we aren't hiding FILE's internals anymore. Notes: svn path=/head/; revision=178782
* Expose FILE's internals to the world again in all their glory. RestoreJohn Baldwin2008-05-0510-140/+23
| | | | | | | | all the previous inline optimizations as well. FILE is back to using __mbstate_t, struct pthread *, and struct pthread_mutex *. Notes: svn path=/head/; revision=178778
* Add __fgetcookie(), __fgetpendout() and __fsetfileno() to the privateMarcel Moolenaar2008-05-041-0/+6
| | | | | | | name space. Notes: svn path=/head/; revision=178756
* Unbreak build: gnu sort has been configured to grope inside structMarcel Moolenaar2008-05-031-0/+7
| | | | | | | | | | __sFILE. It's opaque now, so add a function that returns the pending output bytes. Pointy hat: jhb Notes: svn path=/head/; revision=178755
* Unbreak build: libftpio gropes inside struct __sFILE. ImplementMarcel Moolenaar2008-05-031-0/+14
| | | | | | | | | | | accessor functions for its benefit now thaat FILE is opaque. I'm sure there's a better way. I leave that for people to work on in a src tree that isn't broken. Pointy hat: jhb Notes: svn path=/head/; revision=178747