From: eck Date: Wed, 4 Apr 1990 15:52:01 +0000 (+0000) Subject: improved _doscan(); fflush() doesn't call fseek() anymore X-Git-Tag: release-5-5~1754 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=d87444a7fb3c97a24cb66818bb3acd6280fc951d;p=ack.git improved _doscan(); fflush() doesn't call fseek() anymore --- diff --git a/lang/cem/libcc.ansi/stdio/doscan.c b/lang/cem/libcc.ansi/stdio/doscan.c index 8c4fffbaa..51ac50dcd 100644 --- a/lang/cem/libcc.ansi/stdio/doscan.c +++ b/lang/cem/libcc.ansi/stdio/doscan.c @@ -266,7 +266,8 @@ _doscan(register FILE *stream, const char *format, va_list ap) return done; } str = o_collect(ic, stream, kind, width, &base); - if (str < inp_buf) return done; + if (str < inp_buf + || (str == inp_buf && *str == '-')) return done; nrchars += str - inp_buf + 1; if (!(flags & FL_NOASSIGN)) { if (kind == 'd' || kind == 'i') @@ -415,7 +416,8 @@ _doscan(register FILE *stream, const char *format, va_list ap) if (!width) return done; str = f_collect(ic, stream, width); - if (str < inp_buf) return done; + if (str < inp_buf + || (str == inp_buf && *str == '-')) return done; nrchars += str - inp_buf + 1; if (!(flags & FL_NOASSIGN)) { ld_val = strtod(inp_buf, &tmp_string); @@ -433,5 +435,5 @@ _doscan(register FILE *stream, const char *format, va_list ap) } /* end switch */ ++format; } - return conv ? done : EOF; + return conv || (ic != EOF) ? done : EOF; } diff --git a/lang/cem/libcc.ansi/stdio/fflush.c b/lang/cem/libcc.ansi/stdio/fflush.c index 24f1a3810..018ff2c22 100644 --- a/lang/cem/libcc.ansi/stdio/fflush.c +++ b/lang/cem/libcc.ansi/stdio/fflush.c @@ -27,7 +27,15 @@ fflush(FILE *stream) && !io_testflag(stream, _IOWRITING))) return 0; if (io_testflag(stream, _IOREADING)) { - (void) fseek(stream, 0L, SEEK_CUR); + /* (void) fseek(stream, 0L, SEEK_CUR); */ + int adjust = 0; + if (stream->_buf && !io_testflag(stream,_IONBF)) + adjust = stream->_count; + stream->_count = 0; + _lseek(fileno(stream), (off_t) adjust, SEEK_CUR); + if (io_testflag(stream, _IOWRITE)) + stream->_flags &= ~(_IOREADING | _IOWRITING); + stream->_ptr = stream->_buf; return 0; } else if (io_testflag(stream, _IONBF)) return 0;