summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-03-17 07:07:34 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-03-17 07:07:34 -0700
commitc3e3fc89c9b3832f2c90eec67ad5134d244ea31c (patch)
treefd3704516f0b96df3a069182e8e5dbfaa1bda60f
parent71826056736b40a12027ddb94558febeb9093d61 (diff)
downloadtxr-c3e3fc89c9b3832f2c90eec67ad5134d244ea31c.tar.gz
txr-c3e3fc89c9b3832f2c90eec67ad5134d244ea31c.tar.bz2
txr-c3e3fc89c9b3832f2c90eec67ad5134d244ea31c.zip
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.
-rw-r--r--linenoise/linenoise.c7
1 files changed, 6 insertions, 1 deletions
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);
}