From 3ddafae731eaede5795f519e04ec40dcd44aae92 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 5 Dec 2014 14:48:21 +0000 Subject: vi: failure to open file is not an error when initialising buffer Commit 32afd3a introduced these regressions on the master branch: Starting vi with no filename on the command line gives the status message "'(null)' Bad address" instead of "- No file 1/1 100%". Starting vi with a non-existent file on the command line gives the status message "'new.txt' No such file or directory" instead of "- new.txt 1/1 100%" --- editors/vi.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/editors/vi.c b/editors/vi.c index 0c6906c6b..84da6db74 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -542,9 +542,6 @@ static void cookmode(void); // return to "cooked" mode on tty static int mysleep(int); static int readit(void); // read (maybe cursor) key from stdin static int get_one_char(void); // read 1 char from stdin -#if !ENABLE_FEATURE_VI_READONLY -#define file_insert(fn, p, update_ro_status) file_insert(fn, p) -#endif // file_insert might reallocate text[]! static int file_insert(const char *, char *, int); static int file_write(char *, char *, char *); @@ -1325,7 +1322,7 @@ static void colon(char *buf) q = next_line(q); { // dance around potentially-reallocated text[] uintptr_t ofs = q - text; - size = file_insert(fn, q, /*update_ro:*/ 0); + size = file_insert(fn, q, 0); q = text + ofs; } if (size < 0) @@ -2914,7 +2911,7 @@ static char *get_input_line(const char *prompt) } // might reallocate text[]! -static int file_insert(const char *fn, char *p, int update_ro_status) +static int file_insert(const char *fn, char *p, int initial) { int cnt = -1; int fd, size; @@ -2927,7 +2924,8 @@ static int file_insert(const char *fn, char *p, int update_ro_status) fd = open(fn, O_RDONLY); if (fd < 0) { - status_line_bold_errno(fn); + if (!initial) + status_line_bold_errno(fn); return cnt; } @@ -2975,7 +2973,7 @@ static int file_insert(const char *fn, char *p, int update_ro_status) close(fd); #if ENABLE_FEATURE_VI_READONLY - if (update_ro_status + if (initial && ((access(fn, W_OK) < 0) || /* root will always have access() * so we check fileperms too */ -- cgit v1.2.3-55-g6feb