diff options
author | Ron Yorston <rmy@pobox.com> | 2014-12-05 14:48:21 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2014-12-05 14:48:21 +0000 |
commit | 3ddafae731eaede5795f519e04ec40dcd44aae92 (patch) | |
tree | 898507431fa89bb85c07bd34118bd828e10d5c5c | |
parent | bec486664a470cafb655fa62627784ad27fa4c67 (diff) | |
download | busybox-w32-3ddafae731eaede5795f519e04ec40dcd44aae92.tar.gz busybox-w32-3ddafae731eaede5795f519e04ec40dcd44aae92.tar.bz2 busybox-w32-3ddafae731eaede5795f519e04ec40dcd44aae92.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%"
-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 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 | |||
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) |
@@ -2914,7 +2911,7 @@ static char *get_input_line(const char *prompt) | |||
2914 | } | 2911 | } |
2915 | 2912 | ||
2916 | // might reallocate text[]! | 2913 | // might reallocate text[]! |
2917 | static int file_insert(const char *fn, char *p, int update_ro_status) | 2914 | static int file_insert(const char *fn, char *p, int initial) |
2918 | { | 2915 | { |
2919 | int cnt = -1; | 2916 | int cnt = -1; |
2920 | int fd, size; | 2917 | int fd, size; |
@@ -2927,7 +2924,8 @@ static int file_insert(const char *fn, char *p, int update_ro_status) | |||
2927 | 2924 | ||
2928 | fd = open(fn, O_RDONLY); | 2925 | fd = open(fn, O_RDONLY); |
2929 | if (fd < 0) { | 2926 | if (fd < 0) { |
2930 | status_line_bold_errno(fn); | 2927 | if (!initial) |
2928 | status_line_bold_errno(fn); | ||
2931 | return cnt; | 2929 | return cnt; |
2932 | } | 2930 | } |
2933 | 2931 | ||
@@ -2975,7 +2973,7 @@ static int file_insert(const char *fn, char *p, int update_ro_status) | |||
2975 | close(fd); | 2973 | close(fd); |
2976 | 2974 | ||
2977 | #if ENABLE_FEATURE_VI_READONLY | 2975 | #if ENABLE_FEATURE_VI_READONLY |
2978 | if (update_ro_status | 2976 | if (initial |
2979 | && ((access(fn, W_OK) < 0) || | 2977 | && ((access(fn, W_OK) < 0) || |
2980 | /* root will always have access() | 2978 | /* root will always have access() |
2981 | * so we check fileperms too */ | 2979 | * so we check fileperms too */ |