From c3e3fc89c9b3832f2c90eec67ad5134d244ea31c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 17 Mar 2017 07:07:34 -0700 Subject: linenoise: close descriptor before external edit. * linenoise/linenoise.c (edit_in_editor): Close the file stream after writing out the temporary file, before launching the editor. On Windows, Notepad complains that the file is in use by another application and cannot write to it. Windows Vim treats the file as read-only in spite of good permissions. --- linenoise/linenoise.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 524324e4..50422e50 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -1666,6 +1666,9 @@ static void edit_in_editor(lino_t *l) { FILE *fi; int nread; + fclose(fo); + fo = 0; + if (system(cmd) == 0 && (fi = fopen(path, "r")) != 0) { nread = fread(l->data, 1, sizeof l->data - 1, fi); fclose(fi); @@ -1682,7 +1685,9 @@ static void edit_in_editor(lino_t *l) { } } - fclose(fo); + if (fo != 0) + fclose(fo); + remove(path); clear_sel(l); } -- cgit v1.2.3