summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--stream.c23
-rw-r--r--txr.16
3 files changed, 25 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index 788f2396..5f542085 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2015-07-06 Kaz Kylheku <kaz@kylheku.com>
+ 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.
+
+2015-07-06 Kaz Kylheku <kaz@kylheku.com>
+
Tightening behavior for unimplemented stream ops.
In many cases, if a stream operation is not applicable to a stream, it
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 =
diff --git a/txr.1 b/txr.1
index 0afc90c3..2eeea9c6 100644
--- a/txr.1
+++ b/txr.1
@@ -24228,6 +24228,9 @@ The
function removes the error situation from a stream. On some streams, it does
nothing. If an error has occurred on a stream, this function should be called
prior to re-trying any I/O or positioning operations.
+The return value is the previous error code, or
+.code nil
+if there was no error, or the operation is not supported on the stream.
.coNP Functions @, get-line @ get-char and @ get-byte
.synb
@@ -24452,7 +24455,8 @@ causes all accumulated data inside
.meta stream
to be passed
to the operating system. If called on streams for which this function is not
-meaningful, it does nothing.
+meaningful, it does nothing, and returns
+.codn nil .
.coNP Function @ seek-stream
.synb