[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH 3/8] vi: saving unnamed file in readonly mode
From:       Ron Yorston <rmy () pobox ! com>
Date:       2021-04-25 10:52:55
Message-ID: 60854a07.o1k+nHVXbpc3KmQi%rmy () pobox ! com
[Download RAW message or body]

Suppose vi is started with the command 'vi -R', that is, in readonly
mode with no filename.  Attempting to save the file with 'ZZ' or ':w'
results in the message:

   '(null)' is read only

Skip the code which prints this if no filename was provided, thus
falling through to file_write() which gives the more helpful message
'No current filename'.

function                                             old     new   delta
colon                                               3867    3874      +7
do_cmd                                              4668    4673      +5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 12/0)               Total: 12 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
---
 editors/vi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/editors/vi.c b/editors/vi.c
index d818127e2..a38f2189d 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -3054,7 +3054,7 @@ static void colon(char *buf)
 			fn = args;
 		}
 # if ENABLE_FEATURE_VI_READONLY
-		else if (readonly_mode && !useforce) {
+		else if (readonly_mode && !useforce && fn) {
 			status_line_bold("'%s' is read only", fn);
 			goto ret;
 		}
@@ -3996,7 +3996,7 @@ static void do_cmd(int c)
 			break;
 		}
 		if (modified_count) {
-			if (ENABLE_FEATURE_VI_READONLY && readonly_mode) {
+			if (ENABLE_FEATURE_VI_READONLY && readonly_mode && current_filename) {
 				status_line_bold("'%s' is read only", current_filename);
 				break;
 			}
-- 
2.30.2

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic