From da7ec2ff9c0b6150071c4252eb62d8dc21d0287a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 15 Feb 2019 07:58:46 -0800 Subject: linenoise: preserve too-large-to-read file. * linenoise.c (edit_in_editor): If we can't read the file, then preserve the file, and replace the command line buffer with an error message in which the name of that file appears. --- linenoise/linenoise.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 7e22d21f..4caeb35d 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -1937,6 +1937,7 @@ static void edit_in_editor(lino_t *l) { if (fo) { char cmd[256]; snprintf(cmd, sizeof cmd, "%s %s", ed, path); + int preserve = 0; tr(l->data, '\r', '\n'); if (lino_os.puts_fn(fo, l->data) && lino_os.puts_fn(fo, L"\n")) @@ -1953,7 +1954,13 @@ static void edit_in_editor(lino_t *l) { record_undo(l); - l->data[len] = 0; + if (len == nelem(l->data) - 1) { + wcsnprintf(l->data, nelem(l->data), + L"%s: too large to read, preserved.", + path); + preserve = 1; + len = wcslen(l->data); + } if (len > 0 && l->data[len - 1] == '\n') l->data[--len] = 0; l->dpos = l->dlen = len; @@ -1966,7 +1973,9 @@ static void edit_in_editor(lino_t *l) { if (fo != 0) lino_os.close_fn(fo); - remove(path); + if (!preserve) + remove(path); + clear_sel(l); } } -- cgit v1.2.3