From f1086fe65e26498eb4135daf57d7c9089ecba6a8 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 25 Jan 2019 21:20:12 -0800 Subject: streams: use Boolean return value for stdio_fseek. * stream.c (stdio_seek): Handle new-style Boolean return from stdio_fseek. * sysif.c (stdio_fseek): Return an int indication that is 1 for success, 0 for failure. There was a mistaken assumption here that fseeko returns the file offset, and the return value in the fseek case was mistakenly harmonized, using a wasteful call to stdio_ftell. The only call to this function relies only on a Boolean success/fail indication. * sysif.h (stdio_fseek): Declaration updated. --- stream.c | 2 +- sysif.c | 7 +++---- sysif.h | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/stream.c b/stream.c index 7aae2d5a..53e76afb 100644 --- a/stream.c +++ b/stream.c @@ -675,7 +675,7 @@ static val stdio_seek(val stream, val offset, enum strm_whence whence) if (offset == zero && whence == strm_cur) { return stdio_ftell(h->f); } else { - if (stdio_fseek(h->f, offset, whence) != negone) { + if (stdio_fseek(h->f, offset, whence)) { utf8_decoder_init(&h->ud); h->unget_c = nil; return t; diff --git a/sysif.c b/sysif.c index ae469b07..04ed6ea5 100644 --- a/sysif.c +++ b/sysif.c @@ -1364,14 +1364,13 @@ val stdio_ftell(FILE *f) #endif } -val stdio_fseek(FILE *f, val off, int whence) +int stdio_fseek(FILE *f, val off, int whence) { val self = lit("seek-stream"); #if HAVE_FSEEKO - return num_off_t(fseeko(f, off_t_num(off, self), whence)); + return fseeko(f, off_t_num(off, self), whence) == 0; #else - int ret = fseek(f, c_long(off, self), whence); - return (ret == -1) ? num_fast(ret) : stdio_ftell(f); + return fseek(f, c_long(off, self), whence) == 0; #endif } diff --git a/sysif.h b/sysif.h index 02a5a1da..4e971e3d 100644 --- a/sysif.h +++ b/sysif.h @@ -59,7 +59,7 @@ val statf(val path); off_t off_t_num(val num, val self); val num_off_t(off_t offnum); val stdio_ftell(FILE *); -val stdio_fseek(FILE *, val, int whence); +int stdio_fseek(FILE *, val, int whence); #if HAVE_GETEUID void repress_privilege(void); void drop_privilege(void); -- cgit v1.2.3