summaryrefslogtreecommitdiffstats
path: root/stream.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-07-06 07:20:18 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-07-06 07:20:18 -0700
commit8b3d6f7449e73781e4442aed029b55810b04c75e (patch)
tree27d1ce418e9ccbfb9a4b440c6e9bc42652833b36 /stream.h
parent1ed668849f55baabd50a87375a94ae89f7c5f4b7 (diff)
downloadtxr-8b3d6f7449e73781e4442aed029b55810b04c75e.tar.gz
txr-8b3d6f7449e73781e4442aed029b55810b04c75e.tar.bz2
txr-8b3d6f7449e73781e4442aed029b55810b04c75e.zip
Tightening behavior for unimplemented stream ops.
In many cases, if a stream operation is not applicable to a stream, it is not appropriate to just do nothing and return nil. An error must be thrown. * stream.c (unimpl, unimpl_put_string, unimpl_put_char, unimpl_put_byte, unimpl_get_line, unimpl_get_char, unimpl_get_byte, unimpl_unget_char, unimpl_unget_byte, unimpl_seek, null_put_string, null_put_char, null_put_byte, null_get_line, null_get_char, null_get_byte, null_close, null_flush, null_seek, null_set_prop, null_get_error, null_get_error_str, null_clear_error): New static functions. (fill_stream_ops): New function. (null_ops): Use null_put_string, etc., instead of null pointers. (stdio_clear_error, dir_clear_error, cat_clear_error): Return value now indicating whether an error was cleared. (stream_set_prop, stream_get_prop, real_time_stream_p, close_stream, get_error, get_error_str, clear_error, get_line, get_char, get_byte, unget_char, unget_byte, put_string, put_char, put_byte, flush_stream): Do not test whether a function in the ops table is defined; just call it, and return its value. (stream_init): Call fill_stream_ops on all stream operation structures so any null pointers are defaulted to appropriate functions. * stream.h (struct strm_ops): clear_error gets return value. (fill_stream_ops): Declared. * syslog.c (syslog_init): Call fill_stream_ops on syslog_strm_ops.
Diffstat (limited to 'stream.h')
-rw-r--r--stream.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/stream.h b/stream.h
index ed947577..2162045e 100644
--- a/stream.h
+++ b/stream.h
@@ -47,7 +47,7 @@ struct strm_ops {
val (*set_prop)(val, val ind, val);
val (*get_error)(val);
val (*get_error_str)(val);
- void (*clear_error)(val);
+ val (*clear_error)(val);
};
#define strm_ops_init(cobj_init_macro, put_string, put_char, put_byte, \
@@ -77,6 +77,7 @@ extern val format_s;
extern val stdin_s, stdout_s, stddebug_s, stderr_s, stdnull_s;
+void fill_stream_ops(struct strm_ops *ops);
val make_null_stream(void);
val make_stdio_stream(FILE *, val descr);
val make_tail_stream(FILE *, val descr);