diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2020-02-07 19:47:25 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2020-02-07 19:47:25 -0800 |
commit | 418f661cedc045889b23a0f2881a7049b3d008a4 (patch) | |
tree | b14f981b5f75759fa8f7b80631afba75c29339e4 /stream.h | |
parent | 177964f81055367da1b7aec8638dfc8a63ec99c5 (diff) | |
download | txr-418f661cedc045889b23a0f2881a7049b3d008a4.tar.gz txr-418f661cedc045889b23a0f2881a7049b3d008a4.tar.bz2 txr-418f661cedc045889b23a0f2881a7049b3d008a4.zip |
New "m" file open mode: non-truncating "w".
Quite surprisingly ISO C lacks a way in fopen to open a file
for writing such that it is not truncated if it already
exists, and not opened in append mode.
(But you will be glad to know that ISO C is adding incredibly
useful features in this area, like Microsoft's fopen_s!)
Let us add modes "m" and "m+" which will be like "w" and "w+",
but without the truncation to zero length (no O_TRUNC
is passed to open).
* stream.c (w_fopen_mode): New static function.
(open_file, open_tail, tail_strategy): Use w_fopen_mode
instead of directly calling w_fopen.
(do_parse_mode): Handle 'm' and set new notrunc flag.
* stream.h (struct stdio_mode): New member, notrunc flag.
(stdio_mode_init_blank, stdio_mode_init_r,
stdio_mode_init_rpb): Initializer macros updated to include
initializer for notrunc flag.
* txr.1: Documented "m" mode.
Diffstat (limited to 'stream.h')
-rw-r--r-- | stream.h | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -108,6 +108,7 @@ struct stdio_mode { unsigned create : 1; unsigned append : 1; unsigned binary : 1; + unsigned notrunc : 1; unsigned interactive : 1; unsigned unbuf : 1; unsigned linebuf : 1; @@ -115,9 +116,9 @@ struct stdio_mode { int redir[STDIO_MODE_NREDIRS][2]; }; -#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 stdio_mode_init_blank { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1 } +#define stdio_mode_init_r { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, -1 } +#define stdio_mode_init_rpb { 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, -1 } #define std_input (deref(lookup_var_l(nil, stdin_s))) #define std_output (deref(lookup_var_l(nil, stdout_s))) |