diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-02-25 00:38:49 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-02-25 00:38:49 -0800 |
commit | fee5943718c28f2b9e422bf0564ba35870e55d25 (patch) | |
tree | 04cab14b4bd1bfcfdf970b7a631a88a51735fe24 /stream.h | |
parent | 563b6367a572bc50f8fbec2aeff255c258407862 (diff) | |
download | txr-fee5943718c28f2b9e422bf0564ba35870e55d25.tar.gz txr-fee5943718c28f2b9e422bf0564ba35870e55d25.tar.bz2 txr-fee5943718c28f2b9e422bf0564ba35870e55d25.zip |
Introducing persistent error state on streams.
* lib.c (cobj_ops): New function.
* lib.h (cobj_ops): Declared.
* stream.c (null_ops): Initializer updated.
(struct stdio_handle): New member, err.
(stdio_stream_mark): Mark the err member.
(errno_to_string): New static function.
(stdio_maybe_read_error, stdio_maybe_error): Set persistent error
state. Use errno_to_string_function.
(stdio_put_string, stdio_put_char, stdio_put_byte, stdio_seek,
stdio_get_line): Set errno to zero, so that if the underlying
operations do not set errno on err, we don't misinterpret some pervious
errno value as pertaining to the failed stream operation.
(stdio_get_error, stdio_get_error_str, stdio_clear_error): New static
functions.
(stdio_ops, tail_ops, pipe_ops): Update initializer with new functions.
(string_in_get_error, string_in_get_error_str): New static functions.
(string_in_ops): Update initializer with new functions.
(byte_in_get_error, byte_in_get_error_str): New static functions.
(byte_in_ops): Update initializer with new functions.
(string_out_ops, strlist_out_ops): Update initializer with null
pointers for new functions.
(struct dir_handle): New struct type.
(dir_destroy, dir_mark): New functions.
(dir_get_line): Refactor for struct dir_handle context rather than DIR.
Persist error state.
(dir_close): Refactor for struct dir_handle.
(dir_get_error, dir_get_error_str, dir_clear_error): New static functions.
(dir_ops): Update initializer with new functions.
(make_stdio_stream_common): Initialize new err member.
(make_dir_stream): Refactor for struct dir_handle.
(get_error, get_error_str, clear_error): New functions.
(cat_get_error, cat_get_error_str, cat_clear_error): New static
functions.
(cat_stream_ops): Update initializer with new functions.
(stream_init): Register get-error, get-error-str, clear-error intrinsics.
* stream.h (struct strm_ops): New function pointer members, get_error,
get_error_str and clear_error.
(strm_ops_init): Macro extended with new arguments for new function pointers.
(get_error, get_error_str, clear_error): Declared.
* syslog.c (syslog_strm_ops): Update initializer with null
pointers for new functions.
* txr.1: Documented get-error, get-error-str and clear-error.
Diffstat (limited to 'stream.h')
-rw-r--r-- | stream.h | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -45,15 +45,20 @@ struct strm_ops { val (*seek)(val, cnum, enum strm_whence); val (*get_prop)(val, val ind); val (*set_prop)(val, val ind, val); + val (*get_error)(val); + val (*get_error_str)(val); + void (*clear_error)(val); }; #define strm_ops_init(cobj_init_macro, put_string, put_char, put_byte, \ get_line, get_char, get_byte, unget_char, unget_byte, \ - close, flush, seek, get_prop, set_prop) \ + close, flush, seek, get_prop, set_prop, \ + get_error, get_error_str, clear_error) \ { \ cobj_init_macro, put_string, put_char, put_byte, get_line, \ get_char, get_byte, unget_char, unget_byte, \ - close, flush, seek, get_prop, set_prop \ + close, flush, seek, get_prop, set_prop, \ + get_error, get_error_str, clear_error \ } #define std_input (deref(lookup_var_l(nil, stdin_s))) @@ -88,6 +93,9 @@ val real_time_stream_p(val obj); val stream_set_prop(val stream, val ind, val prop); val stream_get_prop(val stream, val ind); val close_stream(val stream, val throw_on_error); +val get_error(val stream); +val get_error_str(val stream); +val clear_error(val stream); val get_line(val); val get_char(val); val get_byte(val); |