summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/rewind.c
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2001-08-17 09:57:11 +0000
committerache <ache@FreeBSD.org>2001-08-17 09:57:11 +0000
commitca91420dc83eb61f050e2c2e5c063ad0b8ab2b4c (patch)
tree1ac14d62b577338fdc2eef8fa860217334dddad7 /lib/libc/stdio/rewind.c
parent141c7ecefc74015b064137ab8e39f6582bec1697 (diff)
downloadFreeBSD-src-ca91420dc83eb61f050e2c2e5c063ad0b8ab2b4c.zip
FreeBSD-src-ca91420dc83eb61f050e2c2e5c063ad0b8ab2b4c.tar.gz
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()
Diffstat (limited to 'lib/libc/stdio/rewind.c')
-rw-r--r--lib/libc/stdio/rewind.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/libc/stdio/rewind.c b/lib/libc/stdio/rewind.c
index c4de2c1..af9232a 100644
--- a/lib/libc/stdio/rewind.c
+++ b/lib/libc/stdio/rewind.c
@@ -52,9 +52,13 @@ static const char rcsid[] =
void
rewind(FILE *fp)
{
+ /* make sure stdio is set up */
+ if (!__sdidinit)
+ __sinit();
+
FLOCKFILE(fp);
- (void) _fseeko(fp, (off_t)0, SEEK_SET);
- clearerr(fp);
+ if (_fseeko(fp, (off_t)0, SEEK_SET, 1) == 0)
+ clearerr_unlocked(fp);
FUNLOCKFILE(fp);
- errno = 0; /* not required, but seems reasonable */
+ /* errno required by POSIX to sense error, don't zero it here */
}
OpenPOWER on IntegriCloud