diff options
| author | Paul Fox <pgf@brightstareng.com> | 2005-10-09 14:43:22 +0000 |
|---|---|---|
| committer | Paul Fox <pgf@brightstareng.com> | 2005-10-09 14:43:22 +0000 |
| commit | 61e45dbb2f55dfcebf874c6ec3d41f50b284590f (patch) | |
| tree | 8fd46347494d70bd0927066e349d7d375f01e66b | |
| parent | 90372ed51a4a396715dfefef4c3716e6b2ceca11 (diff) | |
| download | busybox-w32-61e45dbb2f55dfcebf874c6ec3d41f50b284590f.tar.gz busybox-w32-61e45dbb2f55dfcebf874c6ec3d41f50b284590f.tar.bz2 busybox-w32-61e45dbb2f55dfcebf874c6ec3d41f50b284590f.zip | |
catch and report errors from file_write()
| -rw-r--r-- | editors/vi.c | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/editors/vi.c b/editors/vi.c index cc2332543..1cc127036 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
| @@ -283,7 +283,6 @@ static void refresh(int); // update the terminal from screen[] | |||
| 283 | 283 | ||
| 284 | static void Indicate_Error(void); // use flash or beep to indicate error | 284 | static void Indicate_Error(void); // use flash or beep to indicate error |
| 285 | #define indicate_error(c) Indicate_Error() | 285 | #define indicate_error(c) Indicate_Error() |
| 286 | |||
| 287 | static void Hit_Return(void); | 286 | static void Hit_Return(void); |
| 288 | 287 | ||
| 289 | #ifdef CONFIG_FEATURE_VI_SEARCH | 288 | #ifdef CONFIG_FEATURE_VI_SEARCH |
| @@ -1113,13 +1112,18 @@ static void colon(Byte * buf) | |||
| 1113 | // system(syscmd); | 1112 | // system(syscmd); |
| 1114 | forced = FALSE; | 1113 | forced = FALSE; |
| 1115 | } | 1114 | } |
| 1116 | psb("\"%s\" %dL, %dC", fn, li, l); | 1115 | if (l < 0) { |
| 1117 | if (q == text && r == end - 1 && l == ch) { | 1116 | if (l == -1) |
| 1118 | file_modified = 0; | 1117 | psbs("Write error: %s", strerror(errno)); |
| 1119 | last_file_modified = -1; | 1118 | } else { |
| 1120 | } | 1119 | psb("\"%s\" %dL, %dC", fn, li, l); |
| 1121 | if ((cmd[0] == 'x' || cmd[1] == 'q') && l == ch) { | 1120 | if (q == text && r == end - 1 && l == ch) { |
| 1122 | editing = 0; | 1121 | file_modified = 0; |
| 1122 | last_file_modified = -1; | ||
| 1123 | } | ||
| 1124 | if ((cmd[0] == 'x' || cmd[1] == 'q') && l == ch) { | ||
| 1125 | editing = 0; | ||
| 1126 | } | ||
| 1123 | } | 1127 | } |
| 1124 | #ifdef CONFIG_FEATURE_VI_READONLY | 1128 | #ifdef CONFIG_FEATURE_VI_READONLY |
| 1125 | vc3:; | 1129 | vc3:; |
| @@ -1147,6 +1151,7 @@ colon_s_fail: | |||
| 1147 | psb(":s expression missing delimiters"); | 1151 | psb(":s expression missing delimiters"); |
| 1148 | #endif | 1152 | #endif |
| 1149 | } | 1153 | } |
| 1154 | |||
| 1150 | #endif /* CONFIG_FEATURE_VI_COLON */ | 1155 | #endif /* CONFIG_FEATURE_VI_COLON */ |
| 1151 | 1156 | ||
| 1152 | static void Hit_Return(void) | 1157 | static void Hit_Return(void) |
| @@ -2516,7 +2521,7 @@ static int file_write(Byte * fn, Byte * first, Byte * last) | |||
| 2516 | 2521 | ||
| 2517 | if (fn == 0) { | 2522 | if (fn == 0) { |
| 2518 | psbs("No current filename"); | 2523 | psbs("No current filename"); |
| 2519 | return (-1); | 2524 | return (-2); |
| 2520 | } | 2525 | } |
| 2521 | charcnt = 0; | 2526 | charcnt = 0; |
| 2522 | // FIXIT- use the correct umask() | 2527 | // FIXIT- use the correct umask() |
| @@ -3440,11 +3445,16 @@ key_cmd_mode: | |||
| 3440 | strncasecmp((char *) p, "wq", cnt) == 0 || | 3445 | strncasecmp((char *) p, "wq", cnt) == 0 || |
| 3441 | strncasecmp((char *) p, "x", cnt) == 0) { | 3446 | strncasecmp((char *) p, "x", cnt) == 0) { |
| 3442 | cnt = file_write(cfn, text, end - 1); | 3447 | cnt = file_write(cfn, text, end - 1); |
| 3443 | file_modified = 0; | 3448 | if (cnt < 0) { |
| 3444 | last_file_modified = -1; | 3449 | if (cnt == -1) |
| 3445 | psb("\"%s\" %dL, %dC", cfn, count_lines(text, end - 1), cnt); | 3450 | psbs("Write error: %s", strerror(errno)); |
| 3446 | if (p[0] == 'x' || p[1] == 'q') { | 3451 | } else { |
| 3447 | editing = 0; | 3452 | file_modified = 0; |
| 3453 | last_file_modified = -1; | ||
| 3454 | psb("\"%s\" %dL, %dC", cfn, count_lines(text, end - 1), cnt); | ||
| 3455 | if (p[0] == 'x' || p[1] == 'q') { | ||
| 3456 | editing = 0; | ||
| 3457 | } | ||
| 3448 | } | 3458 | } |
| 3449 | } else if (strncasecmp((char *) p, "file", cnt) == 0 ) { | 3459 | } else if (strncasecmp((char *) p, "file", cnt) == 0 ) { |
| 3450 | last_status_cksum = 0; // force status update | 3460 | last_status_cksum = 0; // force status update |
| @@ -3630,7 +3640,10 @@ key_cmd_mode: | |||
| 3630 | #endif /* CONFIG_FEATURE_VI_READONLY */ | 3640 | #endif /* CONFIG_FEATURE_VI_READONLY */ |
| 3631 | ) { | 3641 | ) { |
| 3632 | cnt = file_write(cfn, text, end - 1); | 3642 | cnt = file_write(cfn, text, end - 1); |
| 3633 | if (cnt == (end - 1 - text + 1)) { | 3643 | if (cnt < 0) { |
| 3644 | if (cnt == -1) | ||
| 3645 | psbs("Write error: %s", strerror(errno)); | ||
| 3646 | } else if (cnt == (end - 1 - text + 1)) { | ||
| 3634 | editing = 0; | 3647 | editing = 0; |
| 3635 | } | 3648 | } |
| 3636 | } else { | 3649 | } else { |
