summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio
Commit message (Collapse)AuthorAgeFilesLines
* Return -1 instead of 0 upon reaching EOF. This is somewhat ill-adviseddas2009-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@
* Add dprintf() and vdprintf() from POSIX.1-2008. Like getline(),das2009-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.
* Rewrite asprintf() as a wrapper around vasprintf(), thus reducing thedas2009-03-021-43/+22
| | | | | number of functions that have an incestuous relationship with the arcane innards of stdio.
* The argument corresponding to %zn is supposed to be an ssize_t *, notdas2009-03-022-6/+6
| | | | a size_t *, although the distinction is moot in practice.
* Use C99-style initializers. No functional change.das2009-03-011-4/+9
| | | | Reviewed by: md5(1)
* Replace a dozen lines of code with a call to strnlen() / wcsnlen().das2009-02-282-33/+2
|
* - Add getdelim(), getline(), stpncpy(), strnlen(), wcsnlen(),das2009-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@
* Make sure %zd treats negative arguments properly on 32-bit platforms.das2009-02-283-5/+8
| | | | | | | Fix harmless but related bugs in %_$zd and %_$tu. PR: 131880 MFC after: 1 week
* Better wording for clearing EOF indicator.trhodes2009-01-281-0/+4
| | | | Submitted by: keramida and jhb
* Remove another comment about clearing EOF indicator.trhodes2009-01-281-4/+1
| | | | Noticed by: bde
* Update the manpage to reflect r145172.das2009-01-281-2/+1
|
* Remove comment about clearerr() being the only method of clearingtrhodes2009-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>
* Add support for multibyte thousands_sep encodings, e.g., U+066C.das2009-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.
* - Add support for multibyte decimal_point encodings, e.g., U+066B.das2009-01-192-23/+49
| | | | | A forthcoming gdtoa import is needed to make this fully work. - Improve the way "nan(...)" is parsed.
* Add support for multibyte decimal_point encodings, e.g., U+066B.das2009-01-192-23/+35
|
* When f[w]printf() is called on an unbuffered file like stdout, itdas2009-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.)
* Simplify printf's inlined output buffering routines. On amd64, thisdas2009-01-171-18/+18
| | | | reduces the code size by about 10% and improves performance slightly.
* Introduce a local variable and use it instead of passed in parameterrdivacky2009-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)
* Reduce code duplication by moving functions that are identical in bothdas2009-01-153-427/+216
| | | | | vfprintf.c and vfwprintf.c (except for char/wchar_t differences) to a common header file.
* Convert the insidious macros that handle printf()'s buffering intodas2009-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.
* Set the error indicator on an attempt to write to a read-only stream.das2009-01-081-0/+1
| | | | | PR: 127335 MFC after: 2 weeks
* Consolidate some variable initializations. No substantive change.das2008-12-112-13/+13
|
* Move the xprintf hook to where it belongs; it shouldn't be in thedas2008-12-101-6/+4
| | | | middle of vfprintf's variable declarations.
* Fix fread() to return a correct value on platforms where sizeof(int) !=ru2008-12-011-1/+1
| | | | | | | sizeof(size_t), i.e. on all 64-bit platforms. Reported by: Andrey V. Elsukov MFC after: 3 days
* Initialize "nconv" to a reasonable value in all code paths. Prior tocperciva2008-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
* Fix a few bugs with the _gettemp() routine which implements mkstemp(),jhb2008-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
* Use arc4random_uniform(3) since modulo size is not power of 2ache2008-07-221-1/+1
|
* Fix a bogon in the previous commit and add some missing error checks.das2008-06-291-9/+12
|
* Correctly handle malloc() failure. While here, reduce the code size adas2008-06-294-103/+162
| | | | bit by removing some calls to the inline function addtype().
* Factor out the code that builds the argument table. We don't need separatedas2008-06-291-130/+47
| | | | | | normal and wide character versions of it. No functional change.
* Reduce the level of duplication between vfprintf() and vfwprintf()das2008-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.
* Begin de-spaghettifying the code that handles positional arguments.das2008-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.
* Remove useless call to getdtablesize(2) in fdopen(3) and its uselessantoine2008-05-101-4/+0
| | | | | | | | | variable nofile. PR: 123109 Submitted by: Christoph Mallon Approved by: rwatson (mentor) MFC after: 1 month
* Retire the __fgetcookie(), __fgetpendout(), and __fsetfileno() accessorsjhb2008-05-052-27/+0
| | | | as we aren't hiding FILE's internals anymore.
* Expose FILE's internals to the world again in all their glory. Restorejhb2008-05-0510-140/+23
| | | | | all the previous inline optimizations as well. FILE is back to using __mbstate_t, struct pthread *, and struct pthread_mutex *.
* Add __fgetcookie(), __fgetpendout() and __fsetfileno() to the privatemarcel2008-05-041-0/+6
| | | | name space.
* Unbreak build: gnu sort has been configured to grope inside structmarcel2008-05-031-0/+7
| | | | | | | __sFILE. It's opaque now, so add a function that returns the pending output bytes. Pointy hat: jhb
* Unbreak build: libftpio gropes inside struct __sFILE. Implementmarcel2008-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
* Next round of stdio changes: Remove all inlining of stdio operations andjhb2008-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
* Fix a leak in the recent fixes for file descriptors > SHRT_MAX. In thejhb2008-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
* Next stage of stdio cleanup: Retire __sFILEX and merge the fields back intojhb2008-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
* Updates for changes in the way printf() handles hex floating pointdas2008-04-121-4/+5
| | | | numbers.
* Add <limits.h> for SHRT_MAX.jhb2008-02-273-0/+3
| | | | Pointy hat to: jhb
* File descriptors are an int, but our stdio FILE object uses a short to holdjhb2008-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
* Move all the xprintf-related symbols to FBSDprivate_1.0.das2007-12-181-9/+13
| | | | Discussed with: deischen, kan, phk
* Catch up with vfprintf.c,v 1.77.das2007-12-181-0/+1
|
* Remove some test instrumentation. (The Symbol.map changes broke it anyway.)das2007-12-092-8/+0
|
* Add rewind() to the list of functions which may fail and set errnoache2007-06-181-1/+2
|
* Add mbstate clear missed in one of the cases.ache2007-06-181-5/+6
| | | | Move overflow check for fseek as early as needed.
* 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.
OpenPOWER on IntegriCloud