summaryrefslogtreecommitdiff
path: root/src/internal/shgetc.c
AgeCommit message (Collapse)AuthorFilesLines
2013-06-22fix major scanf breakage with unbuffered streams, fmemopen, etc.Rich Felker1-0/+1
the shgetc api, used internally in scanf and int/float scanning code to handle field width limiting and pushback, was designed assuming that pushback could be achieved via a simple decrement on the file buffer pointer. this only worked by chance for regular FILE streams, due to the linux readv bug workaround in __stdio_read which moves the last requested byte through the buffer rather than directly back to the caller. for unbuffered streams and streams not using __stdio_read but some other underlying read function, the first character read could be completely lost, and replaced by whatever junk happened to be in the unget buffer. to fix this, simply have shgetc, when it performs an underlying read operation on the stream, store the character read at the -1 offset from the read buffer pointer. this is valid even for unbuffered streams, as they have an unget buffer located just below the start of the zero-length buffer. the check to avoid storing the character when it is already there is to handle the possibility of read-only buffers. no application-exposed FILE types are allowed to use read-only buffers, but sscanf and strto* may use them internally when calling functions which use the shgetc api.
2012-04-16fix buggy limiter handling in shgetcRich Felker1-4/+3
this is needed for upcoming new scanf
2012-04-16fix broken shgetc limiter logic (wasn't working)Rich Felker1-1/+4
2012-04-11fix incorrect initial count in shgetc when data is already bufferedRich Felker1-1/+1
2012-04-10add "scan helper getc" and rework strtod, etc. to use itRich Felker1-0/+24
the immediate benefit is a significant debloating of the float parsing code by moving the responsibility for keeping track of the number of characters read to a different module. by linking shgetc with the stdio buffer logic, counting logic is defered to buffer refill time, keeping the calls to shgetc fast and light. in the future, shgetc will also be useful for integrating the new float code with scanf, which needs to not only count the characters consumed, but also limit the number of characters read based on field width specifiers. shgetc may also become a useful tool for simplifying the integer parsing code.