From 040bf33abb9c840d4c82451216ca2948e787fea6 Mon Sep 17 00:00:00 2001 From: ache Date: Sat, 1 Sep 2001 15:28:24 +0000 Subject: 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. --- lib/libc/stdio/fseek.c | 6 ++++++ lib/libc/stdio/rewind.c | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c index e831347..38a8bf5 100644 --- a/lib/libc/stdio/fseek.c +++ b/lib/libc/stdio/fseek.c @@ -63,6 +63,7 @@ fseek(fp, offset, whence) int whence; { int ret; + int serrno = errno; /* make sure stdio is set up */ if (!__sdidinit) @@ -71,6 +72,8 @@ fseek(fp, offset, whence) FLOCKFILE(fp); ret = _fseeko(fp, (off_t)offset, whence, 1); FUNLOCKFILE(fp); + if (ret == 0) + errno = serrno; return (ret); } @@ -81,6 +84,7 @@ fseeko(fp, offset, whence) int whence; { int ret; + int serrno = errno; /* make sure stdio is set up */ if (!__sdidinit) @@ -89,6 +93,8 @@ fseeko(fp, offset, whence) FLOCKFILE(fp); ret = _fseeko(fp, offset, whence, 0); FUNLOCKFILE(fp); + if (ret == 0) + errno = serrno; return (ret); } diff --git a/lib/libc/stdio/rewind.c b/lib/libc/stdio/rewind.c index af9232a..2db21c78 100644 --- a/lib/libc/stdio/rewind.c +++ b/lib/libc/stdio/rewind.c @@ -52,13 +52,16 @@ static const char rcsid[] = void rewind(FILE *fp) { + int serrno = errno; + /* make sure stdio is set up */ if (!__sdidinit) __sinit(); FLOCKFILE(fp); - if (_fseeko(fp, (off_t)0, SEEK_SET, 1) == 0) + if (_fseeko(fp, (off_t)0, SEEK_SET, 1) == 0) { clearerr_unlocked(fp); + errno = serrno; + } FUNLOCKFILE(fp); - /* errno required by POSIX to sense error, don't zero it here */ } -- cgit v1.1