summaryrefslogtreecommitdiffstats
path: root/stream.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-07-06 07:35:57 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-07-06 07:35:57 -0700
commit567baab047c82c17c7e3d5a16dc508b5abf6cd25 (patch)
treecf320330fef3daa46db221c4fb01ba9ad565ada3 /stream.c
parent8b3d6f7449e73781e4442aed029b55810b04c75e (diff)
downloadtxr-567baab047c82c17c7e3d5a16dc508b5abf6cd25.tar.gz
txr-567baab047c82c17c7e3d5a16dc508b5abf6cd25.tar.bz2
txr-567baab047c82c17c7e3d5a16dc508b5abf6cd25.zip
Clarify clear-error and flush return value.
* stream.c (stdio_clear_error): Return the prior value of h->err. Do not inspect feof(h->f) or ferror(h->f); just clear the error status of the stream. (stdio_close): Set h->err from errno if fclose failed. (dir_clear_error): Return prior value of h->err. * txr.1: Document return value convetion for clear-error, and flush-stream.
Diffstat (limited to 'stream.c')
-rw-r--r--stream.c23
1 files changed, 7 insertions, 16 deletions
diff --git a/stream.c b/stream.c
index 23c2d214..e0bf5bd8 100644
--- a/stream.c
+++ b/stream.c
@@ -486,18 +486,10 @@ static val stdio_get_error_str(val stream)
static val stdio_clear_error(val stream)
{
struct stdio_handle *h = coerce(struct stdio_handle *, stream->co.handle);
- val ret = nil;
-
- if (h->err) {
- h->err = nil;
- ret = t;
- }
-
- if (h->f != 0 && (feof(h->f) || ferror(h->f))) {
+ val ret = h->err;
+ if (h->f != 0)
clearerr(h->f);
- ret = t;
- }
-
+ h->err = nil;
return ret;
}
@@ -614,6 +606,7 @@ static val stdio_close(val stream, val throw_on_error)
int result = fclose(h->f);
h->f = 0;
if (result == EOF && throw_on_error) {
+ h->err = num(errno);
uw_throwf(file_error_s, lit("error closing ~a: ~a/~s"),
stream, num(errno), string_utf8(strerror(errno)), nao);
}
@@ -1372,11 +1365,9 @@ static val dir_get_error_str(val stream)
static val dir_clear_error(val stream)
{
struct dir_handle *h = coerce(struct dir_handle *, stream->co.handle);
- if (h->err) {
- h->err = nil;
- return t;
- }
- return nil;
+ val ret = h->err;
+ h->err = nil;
+ return ret;
}
static struct strm_ops dir_ops =