diff options
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | stream.c | 23 | ||||
-rw-r--r-- | txr.1 | 6 |
3 files changed, 25 insertions, 17 deletions
@@ -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 @@ -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 = @@ -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 |