Commit graph

240 commits

Author SHA1 Message Date
Andrey A. Chernov 751fc77994 Disallow fseek() optimization in internal read buffer, if pointer is moved by
seek. It means that beginning of read buffer becomes not the same as current
file position.
2001-10-23 22:48:00 +00:00
Bruce Evans 18ca70d12d Fixed style bugs in previous commit. 2001-10-15 04:29:06 +00:00
Doug Rabson a387081c63 Make this compile on ia64. 2001-10-14 13:45:33 +00:00
Ruslan Ermilov 32eef9aeb1 mdoc(7) police: Use the new .In macro for #include statements. 2001-10-01 16:09:29 +00:00
Andrey A. Chernov 1b89a29689 1) If __SAPP stream is not seekable, remove __SAPP flag on first call instead
of repeating unsuccessful lseek call on each write (original stdio bug).

2) Save errno accross _sseek call in _swrite to not touch it in case write
success (original stdio bug).

3) Add _sseek error checking back, but only for __SOPT mode now.
2001-09-07 17:16:02 +00:00
Andrey A. Chernov ac206f37a1 For now just back out seek error checking in __SAPP case, it cause problems
with non-seekable streams.  Now here is what here was originally, but it is
ugly, producing unneded seek syscall on each non-seekable stream write.  I'll
think about proper solution later.
2001-09-07 02:13:11 +00:00
Andrey A. Chernov 347a15b2ab When __SOPT is cleared, clear __SOFF too.
NOTE: original stdio bug.
2001-09-03 02:35:10 +00:00
Andrey A. Chernov 5e00917d95 Re-arrange my funopen(3) fix to minimize differences with original stdio code,
no functional changes.

Add fp->_offset optimization in _SAPP+_SOPT case
2001-09-03 02:24:37 +00:00
Andrey A. Chernov aeb7f4bac4 Internal seeks are overoptimized. They should remember fp->_offset only for
plain regular files, i.e. files with __SOPT flag set. Fix it, so ftell(stdout)
always returns the same as lseek(1, 0, 1) now.

NOTE: this bug was in original stdio code
2001-09-02 21:22:00 +00:00
Andrey A. Chernov 778d840e50 Fix bug in off_t overflow checking: if fp->_offset overflows, just remove
__SOFF flag (i.e. we don't have offset) instead of returning EOVERFLOW.
It allows again continious reading from non-stop stream.
2001-09-02 19:52:09 +00:00
Andrey A. Chernov bf351925f7 Typo seek(2) -> lseek(2) 2001-09-02 19:24:07 +00:00
Andrey A. Chernov 924888f977 Move all stdio internal flags processing and setting out of __sread(),
__swrite() and __sseek() to higher level. According to funopen(3) they all
are just wrappers to something like standard read(2), write(2) and
lseek(2), i.e. must not touch stdio internals because they are replaceable
with any other functions knows nothing about stdio internals. See example
of funopen(3) usage in sendmail sources f.e.

NOTE: this is original stdio bug, not result of my range checkin added.
2001-09-02 19:10:10 +00:00
Andrey A. Chernov 35e1a550de Save errno before function call and restore it on success (because many
internal functions there may fail and set (i.e. overwrite) errno in normal
(not error) situation). In original variant errno testing after call
(as POSIX suggest) is wrong when errno overwrite happens.
2001-09-01 15:28:24 +00:00
Andrey A. Chernov d911eb4536 Remove even more unneded checks, original code can't overflows in that place 2001-09-01 15:01:37 +00:00
Andrey A. Chernov 4fd8a4cf24 Remove two checks unneeded now (can't happens) 2001-09-01 14:48:45 +00:00
Andrey A. Chernov 45892fd855 Make fseek(... SEEK_CUR) fails if current file-position is unspecified. 2001-09-01 14:40:01 +00:00
Andrey A. Chernov 3c4d9468b0 Note that prev. commit addition is for ftell/ftello 2001-09-01 14:23:30 +00:00
Andrey A. Chernov 2f5eadff6b Describe ESPIPE as result of unspecified file-position indicator value.
Add more to SEE ALSO section.
2001-09-01 14:11:53 +00:00
Andrey A. Chernov a914951d68 Describe file-position behaviour from POSIX 2001-09-01 14:01:52 +00:00
Andrey A. Chernov 6ff604a73a Strict in the POSIX sence, if file position is unspecified after ungetc() at
0, return that we can't specify it, i.e. error with ESPIPE.
(hint from: "Peter S. Housel" <housel@acm.org>)

Back out sinit() addition, not needed after various code simplifications.
2001-09-01 12:13:33 +00:00
Andrey A. Chernov 6946977c36 If lseek to wrong value sucessfully happens despite all pre-checks, set __SERR
to indicate that stream becomes inconsistent.
2001-09-01 11:21:28 +00:00
Andrey A. Chernov b13ed88361 If position is underflowed, don't try to hide that fact by recovery, just
return EIO and set __SERR to mark stream as inconsistent.
2001-09-01 11:18:53 +00:00
Andrey A. Chernov 65efd81290 Back out disabling ungetc() at 0, use different solution:
keep negative offset internally, but return 0 externally in ftell*()
I.e. use 0 now as 'unspecified value' per POSIX ungetc() description.
2001-09-01 01:56:54 +00:00
Andrey A. Chernov 598bb4cb30 Add originally missing __sinit() call. 2001-08-31 20:36:19 +00:00
Andrey A. Chernov c4b2cc78e3 Simplify offset underflow checks even more 2001-08-31 20:17:32 +00:00
Andrey A. Chernov 711b11769d Describe that we disallow ungetc at offset 0 now. 2001-08-31 20:03:49 +00:00
Andrey A. Chernov 4db40fd143 Disallow ungetc at offset 0 (to prevent negative offset happens), so simplify
checks in ftell.
2001-08-31 19:50:25 +00:00
Andrey A. Chernov 7cf30ace84 Drop buffer first, _then_ ask for real position 2001-08-31 18:54:44 +00:00
Andrey A. Chernov 2ff678f5bb The same big piece of ftell code repeated in 3 places. Simplify things moving
it into one subfunction instead.
Try to use real offset in strange cases.
2001-08-31 18:23:29 +00:00
Andrey A. Chernov ee75810413 If file offset is smaller than internal buffer character left count, just drop
internal buffer and trust offset, not return error.
2001-08-31 14:11:14 +00:00
Andrey A. Chernov 1dfa423639 Initialize _offset to 0 in fopen(), it helps to optimize fseek/ftell 2001-08-31 13:14:49 +00:00
Andrey A. Chernov ca934ebcae Detect fp->_offset overflow on read
Use errno to catch negative seek with -1 offset
2001-08-31 12:55:22 +00:00
Ruslan Ermilov d6002fef6f Use ``.Rv -std'' wherever possible.
Submitted by:	yar
2001-08-31 09:57:38 +00:00
Andrey A. Chernov 57935eeb3d Try to discard some ungetc data in saved internal buffer checks too,
if offset tends to be negative.
2001-08-30 20:49:47 +00:00
Andrey A. Chernov 77f71bc5ac goto dumb; if can't obtain curoff for whence != SEEK_CUR cases, as supposed 2001-08-30 20:19:45 +00:00
Andrey A. Chernov e54bc118c1 Add more EOVERFLOW checks.
When file offset tends to be negative due to internal and ungetc buffers
additions counted, try to discard some ungetc data first, then return EBADF.
Later one can happens if lseek(fileno(fd),...) called f.e. POSIX says that
ungetc beyond beginning of the file results are undefined, so we can just
discard some of ungetc data in that case.

Don't rely on gcc cast when checking for overflow, use OFF_MAX.

Cosmetique.
2001-08-30 19:54:04 +00:00
Andrey A. Chernov b0eeb07b5b Cosmetique fixes from bde 2001-08-26 10:38:29 +00:00
Andrey A. Chernov f0d5097e06 Cosmetique: correct English in comments 2001-08-23 14:49:02 +00:00
Kris Kennaway 6dac8ac9e5 Mark some functions as __printflike() and/or taking const char * arguments
instead of char *.

MFC after:	2 weeks
2001-08-20 12:53:36 +00:00
Andrey A. Chernov c5981656ea Add about rewind+errno, describe ESPIPE, minor formatting. 2001-08-19 08:24:50 +00:00
Andrey A. Chernov 98aa5183a2 Simplify overflow calculations a bit 2001-08-17 11:08:56 +00:00
Andrey A. Chernov 4a9f1ee4e5 Remove extra check, already done in upper level caller, i.e. in
_fseeko()
2001-08-17 10:43:03 +00:00
Andrey A. Chernov 5fdaf178ae Mention ftell & ftello in EOVERFLOW section too. 2001-08-17 10:29:09 +00:00
Andrey A. Chernov b98ba4224b Add more overflow checks in case of fseek() 2001-08-17 10:22:03 +00:00
Andrey A. Chernov 68ce9bfb10 Don't clear "we have offset" flag even if long is overflow for fseek(),
there is no harm to have it, it will reduce next call efforts.
2001-08-17 10:06:46 +00:00
Andrey A. Chernov 71b5a4326d fseek.c:
Resulting fseek() offset must fit in long, required by POSIX (pointed by bde),
so add LONG_MAX and final tests for it.

rewind.c:
1) add missing __sinit() as in fseek() it pretends to be.
2) use clearerr_unlocked() since we already lock stream before _fseeko()
3) don't zero errno at the end, it explicitely required by POSIX as the
only one method to test rewind() error condition.
4) don't clearerr() if error happens in _fseeko()
2001-08-17 09:57:11 +00:00
Dima Dorfman 7bc6682520 Explain the relation of getchar() to getc() in less words.
Submitted by:	ru
2001-08-16 03:09:33 +00:00
Andrey A. Chernov 74b2772824 Use smarter overflow tests
Suggested by: bde
2001-08-15 20:10:38 +00:00
Andrey A. Chernov d9e3eff33a 1) Disallow negative seek as POSIX require for fseek{o} (but not for lseek):
"[EINVAL] ... The resulting file-position indicator would be set to a
negative value."

Moreover, in real life negative seek in stdio cause EOF indicator cleared
and not set again forever even if EOF returned.

2) Catch few possible off_t overflows.

Reviewed by:	arch discussion
2001-08-15 02:07:47 +00:00
Peter Wemm 2b618987fe Rip out the old __stdin/out/err stuff. It was completely 100% useless. :-(
It was foiled because of dynamic copy relocations that caused compile-time
space to be reserved in .bss and at run time a blob of data was copied to
that space and everything used the .bss version..  The problem is that
the space is reserved at compile time, not runtime... So we *still* could
not change the size of FILE.  Sigh.  :-(

Replace it with something that does actually work and really does let us
make 'FILE' extendable.  It also happens to be the same as Linux does in
glibc, but has the slight cost of a pointer.  Note that this is the
same cost that 'fp = fopen(), fprintf(fp, ...); fclose(fp);' has.
Fortunately, actual references to stdin/out/err are not all that common
since we have implicit stdin/out/err-using versions of functions
(printf() vs. fprintf()).
2001-08-13 21:48:44 +00:00