From 8b3d6f7449e73781e4442aed029b55810b04c75e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 6 Jul 2015 07:20:18 -0700 Subject: 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. --- syslog.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'syslog.c') diff --git a/syslog.c b/syslog.c index d4c5fb8a..cfc24cb8 100644 --- a/syslog.c +++ b/syslog.c @@ -45,6 +45,8 @@ val prio_k; +static struct strm_ops syslog_strm_ops; + void syslog_init(void) { reg_var(intern(lit("log-pid"), user_package), num_fast(LOG_PID)); @@ -77,6 +79,8 @@ void syslog_init(void) prio_k = intern(lit("prio"), keyword_package); reg_var(intern(lit("*stdlog*"), user_package), make_syslog_stream(num_fast(LOG_INFO))); + + fill_stream_ops(&syslog_strm_ops); } val openlog_wrap(val wident, val optmask, val facility) -- cgit v1.2.3