diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-03-19 09:39:14 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-03-19 09:39:14 -0700 |
commit | 8d338fb27ee545c4f2fc90963f8d0c70af478b66 (patch) | |
tree | 3f01780645e6407e904e46be74565b7d77832073 /stream.h | |
parent | ea9ba58da58fc03e4b1ae1d6e277dad8189fa920 (diff) | |
download | txr-8d338fb27ee545c4f2fc90963f8d0c70af478b66.tar.gz txr-8d338fb27ee545c4f2fc90963f8d0c70af478b66.tar.bz2 txr-8d338fb27ee545c4f2fc90963f8d0c70af478b66.zip |
Permissive stream open mode strings.
There is more to this patch than just more permissive
mode strings. Now if a socket can be opened with mode
"l2" for instance, and these options are effectively applied
to the socket-specific "r+b" default, not to "r".
* stream.c (parse_mode): New argument specifying a default
mode. The syntax is relaxed, allowing previously required
elements to be omitted.
(normalize_mode): New argument specifying a default mode.
Format mode is always called now, because an input string
is no longer necessarily a valid fopen string even in cases
when it doesn't specify any extensions.
(open_file, open_fileno, open_tail, open_command,
open_process): Use new normalize_mode argument for defaulting;
normalize_mode no longer defaults to "r".
* stream.h (stdio_mode_init_trivial): Macro removed.
(stdio_mode_init_blank, stdio_mode_init_r,
stdio_mode_init_rpb): New initializer macros.
(parse_mode, normalize_mode): Declarations updated.
* socket.c (sock_accept): In datagram socket case, use new
parse_mode argument for defaulting using stdio_mode_init_rpb,
rather than overriding a missing string with "r+b".
(open_sockfd): Likewise, and use new normalize_mode
argument similarly for defaulting the mode on a stream socket.
* txr.1: Documented mode string permissiveness.
Diffstat (limited to 'stream.h')
-rw-r--r-- | stream.h | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -95,7 +95,9 @@ struct stdio_mode { int buforder : 5; }; -#define stdio_mode_init_trivial(read) { 0, read, 0, 0, 0, 0, 0, 0, 0, -1 } +#define stdio_mode_init_blank { 0, 0, 0, 0, 0, 0, 0, 0, 0, -1 } +#define stdio_mode_init_r { 0, 1, 0, 0, 0, 0, 0, 0, 0, -1 } +#define stdio_mode_init_rpb { 0, 1, 1, 0, 0, 1, 0, 0, 0, -1 } #define std_input (deref(lookup_var_l(nil, stdin_s))) #define std_output (deref(lookup_var_l(nil, stdout_s))) @@ -126,8 +128,8 @@ void fill_stream_ops(struct strm_ops *ops); void stream_print_op(val stream, val out, val pretty); void stream_mark_op(val stream); void stream_destroy_op(val stream); -struct stdio_mode parse_mode(val mode_str); -val normalize_mode(struct stdio_mode *m, val mode_str); +struct stdio_mode parse_mode(val mode_str, struct stdio_mode m_dfl); +val normalize_mode(struct stdio_mode *m, val mode_str, struct stdio_mode m_dfl); val set_mode_props(const struct stdio_mode m, val stream); val generic_get_line(val stream); val errno_to_string(val err); |