summaryrefslogtreecommitdiff
path: root/lib/libc/stdio
Commit message (Collapse)AuthorAgeFilesLines
* 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
* Next round of stdio changes: Remove all inlining of stdio operations andJohn Baldwin2008-05-0212-112/+200
| | | | | | | | | | | | | | | | | | | move the definition of the type backing FILE (struct __sFILE) into an internal header. - Remove macros to inline certain operations from stdio.h. Applications will now always call the functions instead. - Move the various foo_unlocked() functions from unlocked.c into foo.c. This lets some of the inlining macros (e.g. __sfeof()) move into foo.c. - Update a few comments. - struct __sFILE can now go back to using mbstate_t, pthread_t, and pthread_mutex_t instead of knowing about their private, backing types. MFC after: 1 month Reviewed by: kan Notes: svn path=/head/; revision=178721
* Fix a leak in the recent fixes for file descriptors > SHRT_MAX. In theJohn Baldwin2008-04-221-0/+1
| | | | | | | | | | | case of a file descriptor we can't handle, clear the FILE structure's flags so it can be reused. MFC after: 1 week Reported by: otto @ OpenBSD Notes: svn path=/head/; revision=178427
* Next stage of stdio cleanup: Retire __sFILEX and merge the fields back intoJohn Baldwin2008-04-1726-143/+72
| | | | | | | | | | | | | | | | | | | | | | __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 Notes: svn path=/head/; revision=178287
* Updates for changes in the way printf() handles hex floating pointDavid Schultz2008-04-121-4/+5
| | | | | | | numbers. Notes: svn path=/head/; revision=178141
* Add <limits.h> for SHRT_MAX.John Baldwin2008-02-273-0/+3
| | | | | | | Pointy hat to: jhb Notes: svn path=/head/; revision=176629
* File descriptors are an int, but our stdio FILE object uses a short to holdJohn Baldwin2008-02-273-0/+39
| | | | | | | | | | | | | | | | | | | | them. Thus, any fd whose value is greater than SHRT_MAX is handled incorrectly (the short value is sign-extended when converted to an int). An unpleasant side effect is that if fopen() opens a file and gets a backing fd that is greater than SHRT_MAX, fclose() will fail and the file descriptor will be leaked. Better handle this by fixing fopen(), fdopen(), and freopen() to fail attempts to use a fd greater than SHRT_MAX with EMFILE. At some point in the future we should look at expanding the file descriptor in FILE to an int, but that is a bit complicated due to ABI issues. MFC after: 1 week Discussed on: arch Reviewed by: wollman Notes: svn path=/head/; revision=176628
* Move all the xprintf-related symbols to FBSDprivate_1.0.David Schultz2007-12-181-9/+13
| | | | | | | Discussed with: deischen, kan, phk Notes: svn path=/head/; revision=174760
* Catch up with vfprintf.c,v 1.77.David Schultz2007-12-181-0/+1
| | | | Notes: svn path=/head/; revision=174733
* Remove some test instrumentation. (The Symbol.map changes broke it anyway.)David Schultz2007-12-092-8/+0
| | | | Notes: svn path=/head/; revision=174495
* Add rewind() to the list of functions which may fail and set errnoAndrey A. Chernov2007-06-181-1/+2
| | | | Notes: svn path=/head/; revision=170908
* Add mbstate clear missed in one of the cases.Andrey A. Chernov2007-06-181-5/+6
| | | | | | | Move overflow check for fseek as early as needed. Notes: svn path=/head/; revision=170907
* We should never zero-pad INF or NaN (yielding silly strings like "00inf")David Schultz2007-05-081-0/+1
| | | | | | | even if the programmer asks for zero padding. Notes: svn path=/head/; revision=169355