summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/fseek.c
Commit message (Collapse)AuthorAgeFilesLines
* Convert libc/stdio from K&R to ANSI Cemaste2013-04-231-13/+3
| | | | And add '__restrict' where it appeared in the header prototypes
* Renumber clauses to reduce diffs to other versionsemaste2013-04-231-1/+1
| | | | | | | NetBSD, OpenBSD, and Android's Bionic all number the clauses 1 through 3, so follow suit to make comparison easier. Acked-by: imp@
* Next stage of stdio cleanup: Retire __sFILEX and merge the fields back intojhb2008-04-171-4/+4
| | | | | | | | | | | | | | | | | | | __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
* Add mbstate clear missed in one of the cases.ache2007-06-181-5/+6
| | | | Move overflow check for fseek as early as needed.
* Per Regents of the University of Calfornia letter, remove advertisingimp2007-01-091-4/+0
| | | | | | clause. # If I've done so improperly on a file, please let me know.
* Associate a multibyte conversion state object with each stream. Reset ittjr2004-05-221-0/+2
| | | | | | | | | to the initial state when a stream is opened or seeked upon. Use the stream's conversion state object instead of a freshly-zeroed one in fgetwc(), fputwc() and ungetwc(). This is only a performance improvement for now, but it would also be required in order to support state-dependent encodings.
* Fix the style of the SCM ID's.obrien2002-03-221-4/+2
| | | | I believe have made all of libc .c's as consistent as possible.
* Remove __P() usage.obrien2002-03-211-1/+1
|
* Remove 'register' keyword.obrien2002-03-211-2/+2
|
* In > LONG_MAX test use sseek return value and not _offset which can be notache2001-10-251-3/+4
| | | | active.
* Help to recover from bad seek (i.e. negative or too big) happens beyondache2001-10-241-5/+5
| | | | | our pre-check control. Do the same way as refill.c does when it set __SERR, i.e. clear read and ungetc buffers. Clear EOF flag too.
* Back out read buffer invalidating via __SMOD.ache2001-10-231-2/+2
| | | | | It was correct, but not needed because internal buffer cleared on each seek outside of it.
* Change comment explaining another usage of __SMODache2001-10-231-2/+2
|
* Re-arrange my funopen(3) fix to minimize differences with original stdio code,ache2001-09-031-39/+0
| | | | | | no functional changes. Add fp->_offset optimization in _SAPP+_SOPT case
* Internal seeks are overoptimized. They should remember fp->_offset only forache2001-09-021-1/+1
| | | | | | | 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
* Move all stdio internal flags processing and setting out of __sread(),ache2001-09-021-3/+41
| | | | | | | | | | __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.
* Save errno before function call and restore it on success (because manyache2001-09-011-0/+6
| | | | | | 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.
* Remove even more unneded checks, original code can't overflows in that placeache2001-09-011-5/+1
|
* Remove two checks unneeded now (can't happens)ache2001-09-011-4/+0
|
* Make fseek(... SEEK_CUR) fails if current file-position is unspecified.ache2001-09-011-2/+6
|
* If lseek to wrong value sucessfully happens despite all pre-checks, set __SERRache2001-09-011-0/+1
| | | | to indicate that stream becomes inconsistent.
* Back out disabling ungetc() at 0, use different solution:ache2001-09-011-10/+19
| | | | | keep negative offset internally, but return 0 externally in ftell*() I.e. use 0 now as 'unspecified value' per POSIX ungetc() description.
* The same big piece of ftell code repeated in 3 places. Simplify things movingache2001-08-311-84/+7
| | | | | it into one subfunction instead. Try to use real offset in strange cases.
* If file offset is smaller than internal buffer character left count, just dropache2001-08-311-9/+21
| | | | internal buffer and trust offset, not return error.
* Try to discard some ungetc data in saved internal buffer checks too,ache2001-08-301-4/+16
| | | | if offset tends to be negative.
* goto dumb; if can't obtain curoff for whence != SEEK_CUR cases, as supposedache2001-08-301-8/+4
|
* Add more EOVERFLOW checks.ache2001-08-301-24/+61
| | | | | | | | | | | | 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.
* Cosmetique fixes from bdeache2001-08-261-2/+0
|
* Cosmetique: correct English in commentsache2001-08-231-2/+2
|
* Simplify overflow calculations a bitache2001-08-171-4/+2
|
* Add more overflow checks in case of fseek()ache2001-08-171-0/+8
|
* Don't clear "we have offset" flag even if long is overflow for fseek(),ache2001-08-171-1/+0
| | | | there is no harm to have it, it will reduce next call efforts.
* fseek.c:ache2001-08-171-5/+23
| | | | | | | | | | | | 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()
* Use smarter overflow testsache2001-08-151-3/+6
| | | | Suggested by: bde
* 1) Disallow negative seek as POSIX require for fseek{o} (but not for lseek):ache2001-08-151-0/+23
| | | | | | | | | | | | "[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
* Fix the current libc breakage in current:imp2001-02-161-1/+1
| | | | | | | | | | | | | o Back out the __std* stuff. Can't figure out how to do this right now, so we'll save it for late. o use _up as a pointer for extra fields that we need to access. o back out the libc major version bump. Submitted by: green reviewed by: peter, imp, green, obrien (to varying degrees). We'll fix the "how do we stop encoding sizeof(FILE) in binaries" part later.
* Remove _THREAD_SAFE and make libc thread-safe by default bydeischen2001-01-241-21/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | adding (weak definitions to) stubs for some of the pthread functions. If the threads library is linked in, the real pthread functions will pulled in. Use the following convention for system calls wrapped by the threads library: __sys_foo - actual system call _foo - weak definition to __sys_foo foo - weak definition to __sys_foo Change all libc uses of system calls wrapped by the threads library from foo to _foo. In order to define the prototypes for _foo(), we introduce namespace.h and un-namespace.h (suggested by bde). All files that need to reference these system calls, should include namespace.h before any standard includes, then include un-namespace.h after the standard includes and before any local includes. <db.h> is an exception and shouldn't be included in between namespace.h and un-namespace.h namespace.h will define foo to _foo, and un-namespace.h will undefine foo. Try to eliminate some of the recursive calls to MT-safe functions in libc/stdio in preparation for adding a mutex to FILE. We have recursive mutexes, but would like to avoid using them if possible. Remove uneeded includes of <errno.h> from a few files. Add $FreeBSD$ to a few files in order to pass commitprep. Approved by: -arch
* $Id$ -> $FreeBSD$peter1999-08-281-1/+1
|
* Added functions fseeko() and ftello() (from susv2).dt1999-02-081-3/+12
| | | | | | | Fixed fgetpos() and fsetpos() for offsets > 2GB. PR: 8637 Submitted by: Dan Nelson <dnelson@emsphone.com> (adjusted by me a little)
* Add FILE locking stubs for libc.jb1998-04-111-26/+10
| | | | | | | | Change the FILE locking to support kernel threads when linked with libpthread (which you haven't see yet). This requires that libc become thread-safe and thread-aware, testing __isthreaded before attempting to do lock/unlock calls. The impact on non-threaded programs is minor. This change works with libc_r, so it's the best compromise.
* Revert $FreeBSD$ to $Id$peter1997-02-221-1/+1
|
* Make the long-awaited change from $Id$ to $FreeBSD$jkh1997-01-141-1/+1
| | | | | | | | This will make a number of things easier in the future, as well as (finally!) avoiding the Id-smashing problem which has plagued developers for so long. Boy, I'm glad we're not using sup anymore. This update would have been insane otherwise.
* Suggested by: Bruce Evans, Jeffrey Hsu, Gary Palmerjraynard1996-06-221-1/+5
| | | | | | | | | | | | | | | | | | | | | Added $Id$'s to files that were lacking them (gpalmer), made some cosmetic changes to conform to style guidelines (bde) and checked against NetBSD and Lite2 to remove unnecessary divergences (hsu, bde) One last code cleanup:- Removed spurious casts in fseek.c and stdio.c. Added missing function argument in fwalk.c. Added missing header include in flags.c and rget.c. Put in casts where int's were being passed as size_t's. Put in missing prototypes for static functions. Changed second args of __sflags() inflags.c and writehook() in vasprintf.c from char * to const char * to conform to prototypes. This directory now compiles with no warnings with -Wall under gcc-2.6.3 and with considerably less warnings than before with the ultra-pedantic script I used for testing. (Most of the remaining ones are due to const poisoning).
* Reviewed by: julian and (hsu?)julian1996-01-221-1/+27
| | | | | | Submitted by: John Birrel(L?) changes for threadsafe operations
* Date: Wed, 26 Oct 1994 15:44:49 -0600nate1994-11-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | From: Chris Torek <torek@bsdi.com> Here is a semi-official patch (apply to /usr/src/lib/libc/stdio/fseek.c, rebuild libc, install). The current code fails when the seek: - is optimized, and - is to just past the end of the block currently in the buffer, and - is followed by another seek with no intervening read operation, and - the destination of subsequent seek is within the block left in the buffer (seeking to the beginning of a block does not force a read, so the buffer still contains the previous block) so it is indeed rather obscure. I may have a different `final' fix, as this one `loses' the buffer contents on a seek that goes just past the end of the current block. [Footnote: seeks are optimized only on read-only opens of regular files that are buffered by the file's optimal I/O size. This is what you get with fopen(path, "r") and no call to setvbuf().] Obtained from: [ BSDI mailing list ]
* BSD 4.4 Lite Lib Sourcesrgrimes1994-05-271-0/+245
OpenPOWER on IntegriCloud