diff options
author | Ron Yorston <rmy@tigress.co.uk> | 2014-11-30 20:39:25 +0000 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-01-07 17:00:48 +0100 |
commit | e5213cee3833a88397cb5e73428efb9a1b886db3 (patch) | |
tree | 4b29617fcc1024e945c6b94877184b5a4271c660 | |
parent | 08364dab752e752ba3b7da30f64d09b72d9da0ad (diff) | |
download | busybox-w32-e5213cee3833a88397cb5e73428efb9a1b886db3.tar.gz busybox-w32-e5213cee3833a88397cb5e73428efb9a1b886db3.tar.bz2 busybox-w32-e5213cee3833a88397cb5e73428efb9a1b886db3.zip |
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%"
Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/vi.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/editors/vi.c b/editors/vi.c index 70bdbab07..7b88e8e17 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -542,9 +542,6 @@ static void cookmode(void); // return to "cooked" mode on tty | |||
542 | static int mysleep(int); | 542 | static int mysleep(int); |
543 | static int readit(void); // read (maybe cursor) key from stdin | 543 | static int readit(void); // read (maybe cursor) key from stdin |
544 | static int get_one_char(void); // read 1 char from stdin | 544 | static int get_one_char(void); // read 1 char from stdin |
545 | #if !ENABLE_FEATURE_VI_READONLY | ||
546 | #define file_insert(fn, p, update_ro_status) file_insert(fn, p) | ||
547 | #endif | ||
548 | // file_insert might reallocate text[]! | 545 | // file_insert might reallocate text[]! |
549 | static int file_insert(const char *, char *, int); | 546 | static int file_insert(const char *, char *, int); |
550 | static int file_write(char *, char *, char *); | 547 | static int file_write(char *, char *, char *); |
@@ -1325,7 +1322,7 @@ static void colon(char *buf) | |||
1325 | q = next_line(q); | 1322 | q = next_line(q); |
1326 | { // dance around potentially-reallocated text[] | 1323 | { // dance around potentially-reallocated text[] |
1327 | uintptr_t ofs = q - text; | 1324 | uintptr_t ofs = q - text; |
1328 | size = file_insert(fn, q, /*update_ro:*/ 0); | 1325 | size = file_insert(fn, q, 0); |
1329 | q = text + ofs; | 1326 | q = text + ofs; |
1330 | } | 1327 | } |
1331 | if (size < 0) | 1328 | if (size < 0) |
@@ -2905,7 +2902,7 @@ static char *get_input_line(const char *prompt) | |||
2905 | } | 2902 | } |
2906 | 2903 | ||
2907 | // might reallocate text[]! | 2904 | // might reallocate text[]! |
2908 | static int file_insert(const char *fn, char *p, int update_ro_status) | 2905 | static int file_insert(const char *fn, char *p, int initial) |
2909 | { | 2906 | { |
2910 | int cnt = -1; | 2907 | int cnt = -1; |
2911 | int fd, size; | 2908 | int fd, size; |
@@ -2918,7 +2915,8 @@ static int file_insert(const char *fn, char *p, int update_ro_status) | |||
2918 | 2915 | ||
2919 | fd = open(fn, O_RDONLY); | 2916 | fd = open(fn, O_RDONLY); |
2920 | if (fd < 0) { | 2917 | if (fd < 0) { |
2921 | status_line_bold_errno(fn); | 2918 | if (!initial) |
2919 | status_line_bold_errno(fn); | ||
2922 | return cnt; | 2920 | return cnt; |
2923 | } | 2921 | } |
2924 | 2922 | ||
@@ -2946,7 +2944,7 @@ static int file_insert(const char *fn, char *p, int update_ro_status) | |||
2946 | close(fd); | 2944 | close(fd); |
2947 | 2945 | ||
2948 | #if ENABLE_FEATURE_VI_READONLY | 2946 | #if ENABLE_FEATURE_VI_READONLY |
2949 | if (update_ro_status | 2947 | if (initial |
2950 | && ((access(fn, W_OK) < 0) || | 2948 | && ((access(fn, W_OK) < 0) || |
2951 | /* root will always have access() | 2949 | /* root will always have access() |
2952 | * so we check fileperms too */ | 2950 | * so we check fileperms too */ |