about summary refs log tree commit diff
path: root/src/stdio
Commit message (Collapse)AuthorAgeFilesLines
* fix crash in dns code with new stdio locking codeRich Felker2011-08-011-0/+1
|
* add proper fuxed-based locking for stdioRich Felker2011-07-3014-39/+44
| | | | | | | | | | | | | | | | | | | | | | previously, stdio used spinlocks, which would be unacceptable if we ever add support for thread priorities, and which yielded pathologically bad performance if an application attempted to use flockfile on a key file as a major/primary locking mechanism. i had held off on making this change for fear that it would hurt performance in the non-threaded case, but actually support for recursive locking had already inflicted that cost. by having the internal locking functions store a flag indicating whether they need to perform unlocking, rather than using the actual recursive lock counter, i was able to combine the conditionals at unlock time, eliminating any additional cost, and also avoid a nasty corner case where a huge number of calls to ftrylockfile could cause deadlock later at the point of internal locking. this commit also fixes some issues with usage of pthread_self conflicting with __attribute__((const)) which resulted in crashes with some compiler versions/optimizations, mainly in flockfile prior to pthread_create.
* eliminate dependence of perror on printfRich Felker2011-07-301-10/+5
|
* fix logic error in freadRich Felker2011-07-161-6/+1
| | | | | | | | fread was calling f->read without checking that the file was in reading mode. this could: 1. crash, if f->read was a null pointer 2. cause unwanted blocking on a terminal already at eof 3. allow reading on a write-only file
* printf: "if a precision is specified, the '0' flag shall be ignored."Rich Felker2011-07-041-1/+1
|
* zero precision with zero value should not inhibit prefix/width printingRich Felker2011-07-041-1/+4
|
* printf("%#x",0) should print 0 not 0x0Rich Felker2011-07-041-1/+1
|
* fix logic in __fwritingRich Felker2011-06-301-1/+1
|
* add and consolidate nasty stdio_ext junkRich Felker2011-06-303-17/+57
| | | | | hopefully this resolves the rest of the issues with hideously nonportable hacks in programs that use gnulib.
* implement the nonstandard GNU function fpurgeRich Felker2011-06-301-0/+11
| | | | | | this is a really ugly and backwards function, but its presence will prevent lots of broken gnulib software from trying to define its own version of fpurge and thereby failing to build or worse.
* avoid 64bit warnings when using pointers as entropy for temp namesRich Felker2011-06-132-2/+4
|
* fix the last known rounding bug in floating point printingRich Felker2011-05-111-3/+4
| | | | | | | | | the observed symptom was that the code was incorrectly rounding up 1.0625 to 1.063 despite the rounding mode being round-to-nearest with ties broken by rounding to even last place. however, the code was just not right in many respects, and i'm surprised it worked as well as it did. this time i tested the values that end up in the variables round, small, and the expression round+small, and all look good.
* reduce some ridiculously large spin countsRich Felker2011-05-061-1/+1
| | | | | | these should be tweaked according to testing. offhand i know 1000 is too low and 5000 is likely to be sufficiently high. consider trying to add futexes to file locking, too...
* fix fclose return status logic, againRich Felker2011-05-021-1/+2
| | | | | | | | the previous fix was incorrect, as it would prevent f->close(f) from being called if fflush(f) failed. i believe this was the original motivation for using | rather than ||. so now let's just use a second statement to constrain the order of function calls, and to back to using |.
* fix undefined call order in fclose, possible lost output depending on compilerRich Felker2011-05-011-1/+1
| | | | | pcc turned up this bug by calling f->close(f) before fflush(f), resulting in lost output and error on flush.
* minor optimization in puts: use inline putc_unlocked macro for newlineRich Felker2011-05-011-1/+1
|
* fix 2 eof-related bugs in scanfRich Felker2011-04-251-3/+4
| | | | | | | | | 1. failed match of literal chars from the format string would always return matching failure rather than input failure at eof, leading to infinite loops in some programs. 2. unread of eof would wrongly adjust the character counts reported by %n, yielding an off-by-one error.
* clean up handling of thread/nothread mode, lockingRich Felker2011-04-172-5/+1
|
* debloat: use __syscall instead of syscall where possibleRich Felker2011-04-174-5/+5
| | | | | | don't waste time (and significant code size due to function call overhead!) setting errno when the result of a syscall does not matter or when it can't fail.
* avoid setting errno when checking for ttyRich Felker2011-04-152-2/+2
| | | | | | | setting errno here is completely valid, but some programs, notably busybox printf, assume that errno will not be set during output and treat this as an error condition. in any case, skipping it slightly reduces code size and saves time.
* make tmpfile slightly more efficient (use unlink syscall instead of remove)Rich Felker2011-04-141-1/+1
|
* fix printf("%.9g", 1.1) and similar not dropping trailing zerosRich Felker2011-04-121-1/+3
|
* fix fputwc return valueRich Felker2011-04-111-1/+1
|
* work around a nasty bug in linux readv syscallRich Felker2011-04-091-3/+4
| | | | | | | | | | | | | | | | according to posix, readv "shall be equivalent to read(), except..." that it places the data into the buffers specified by the iov array. however on linux, when reading from a terminal, each iov element behaves almost like a separate read. this means that if the first iov exactly satisfied the request (e.g. a length-one read of '\n') and the second iov is nonzero length, the syscall will block again after getting the blank line from the terminal until another line is read. simply put, entering a single blank line becomes impossible. the solution, fortunately, is simple. whenever the buffer size is nonzero, reduce the length of the requested read by one byte and let the last byte go through the buffer. this way, readv will already be in the second (and last) iov, and won't re-block on the second iov.
* add more legacy functions: setlinebuf and setbufferRich Felker2011-04-053-1/+15
|
* fix overflow in printf %N$ argument handlingRich Felker2011-04-051-2/+2
|
* fix various floating point rounding and formatting errors in *printfRich Felker2011-04-051-17/+25
|
* simplify vdprintf implementation greatly based on recent vfprintf changesRich Felker2011-04-041-5/+2
| | | | | | | since vfprintf will provide a temporary buffer in the case where the target FILE has a zero buffer size, don't bother setting up a real buffer for vdprintf. this also allows us to skip the call to fflush since we know everything will be written out before vfprintf returns.
* use a local temp buffer for unbuffered streams in vfprintfRich Felker2011-04-042-0/+14
| | | | | | | | | this change makes it so most calls to fprintf(stderr, ...) will result in a single writev syscall, as opposed to roughly 2*N syscalls (and possibly more) where N is the number of format specifiers. in principle we could use a much larger buffer, but it's best not to increase the stack requirements too much. most messages are under 80 chars.
* don't disable seeking after first seek failureRich Felker2011-04-021-8/+0
| | | | | this could cause problems if the application uses dup2(fd,fileno(f)) to redirect, and the old fd was not seekable but the new fd is.
* apparently fseek should not set the error flag on failed seekRich Felker2011-04-021-4/+1
|
* fix tempnam name generation, and a small bug in tmpnam on retry limitRich Felker2011-03-292-21/+20
|
* make tmpfile fail after exceeding max tries.Rich Felker2011-03-291-2/+6
|
* fix tmpnam to generate better names, not depend on non-ISO-C symbolsRich Felker2011-03-291-25/+17
|
* fix messed-up errno if remove fails for a non-EISDIR reasonRich Felker2011-03-291-2/+2
|
* learned something new - remove is supposed to support directories on POSIXRich Felker2011-03-291-1/+3
|
* revert some more spin optimizations that turned out to be pessimizationsRich Felker2011-03-281-1/+1
|
* fix getc - the classic error of trying to store EOF+0-255 in a char type..Rich Felker2011-03-281-3/+3
|
* major stdio overhaul, using readv/writev, plus other changesRich Felker2011-03-2835-268/+235
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | the biggest change in this commit is that stdio now uses readv to fill the caller's buffer and the FILE buffer with a single syscall, and likewise writev to flush the FILE buffer and write out the caller's buffer in a single syscall. making this change required fundamental architectural changes to stdio, so i also made a number of other improvements in the process: - the implementation no longer assumes that further io will fail following errors, and no longer blocks io when the error flag is set (though the latter could easily be changed back if desired) - unbuffered mode is no longer implemented as a one-byte buffer. as a consequence, scanf unreading has to use ungetc, to the unget buffer has been enlarged to hold at least 2 wide characters. - the FILE structure has been rearranged to maintain the locations of the fields that might be used in glibc getc/putc type macros, while shrinking the structure to save some space. - error cases for fflush, fseek, etc. should be more correct. - library-internal macros are used for getc_unlocked and putc_unlocked now, eliminating some ugly code duplication. __uflow and __overflow are no longer used anywhere but these macros. switch to read or write mode is also separated so the code can be better shared, e.g. with ungetc. - lots of other small things.
* fix all implicit conversion between signed/unsigned pointersRich Felker2011-03-256-8/+8
| | | | | | | sadly the C language does not specify any such implicit conversion, so this is not a matter of just fixing warnings (as gcc treats it) but actual errors. i would like to revisit a number of these changes and possibly revise the types used to reduce the number of casts required.
* simplify and optimize FILE lock handlingRich Felker2011-03-244-11/+12
|
* fix non-atomicity of putsRich Felker2011-03-241-1/+5
|
* global cleanup to use the new syscall interfaceRich Felker2011-03-2012-19/+19
|
* implement [v]swprintfRich Felker2011-03-182-0/+60
|
* implement wprintf family of functionsRich Felker2011-03-174-0/+387
| | | | | | | | | this implementation is extremely ugly and inefficient, but it avoids a good deal of code duplication and bloat. it may be cleaned up later to eliminate the remaining code duplication and some of the warts, but i don't really care about its performance. note that swprintf is not yet implemented.
* optimize file locking: avoid cache-polluting writes to global storageRich Felker2011-03-162-3/+5
|
* partially-written draft of fmemopen, still in #if 0Rich Felker2011-03-141-3/+48
|
* implement flockfile api, rework stdio lockingRich Felker2011-03-126-3/+54
|
* rewind must clear the error indicator in addition to seekingRich Felker2011-02-221-2/+5
|
* avoid referencing address of extern function from vdprintfRich Felker2011-02-201-1/+6
| | | | | | | | this change is in preparation for upcoming PIC/shared library support. the intent is to avoid going through the GOT, mainly so that dprintf is operable immediately, prior to processing of relocations. having dprintf accessible from the dynamic linker will make writing and debugging the dynamic linker much easier.