From 418f661cedc045889b23a0f2881a7049b3d008a4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 7 Feb 2020 19:47:25 -0800 Subject: 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. --- txr.1 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'txr.1') diff --git a/txr.1 b/txr.1 index 9765dc2f..6f3f2258 100644 --- a/txr.1 +++ b/txr.1 @@ -48925,7 +48925,7 @@ grammar. Note that it permits no whitespace characters: .mono .mets < mode-string := [ < mode ] [ < options ] .mets < mode := { < selector [ + ] | + } -.mets < selector := { r | w | a } +.mets < selector := { r | w | a | m } .mets < options := { b | l | u | < digit | < redirection } .mets < digit := { 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 } .onom @@ -48968,6 +48968,14 @@ to zero length. If it doesn't exist, it is created. .coIP w+ The file is opened for reading and writing. If it exists, it is truncated to zero length. If it doesn't exist, it is created. +.coIP m +The file is opened for modification. This is the same as +.code w +except that the file is not truncated if it exists. +.coIP m+ +The file is opened for reading and modification. This is the same as +.code w+ +except that the file is not truncated if it exists. .coIP a The file is opened for writing. If it doesn't exist, it is created. If it exists, the current position is advanced to -- cgit v1.2.3