diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-03-17 07:07:34 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-03-17 07:07:34 -0700 |
commit | fbb35f10c305128e865f7c16e21f61ea6e62083e (patch) | |
tree | fd3704516f0b96df3a069182e8e5dbfaa1bda60f /linenoise | |
parent | db2d654347e06fe7e40a498eee02e523936f4a53 (diff) | |
download | txr-fbb35f10c305128e865f7c16e21f61ea6e62083e.tar.gz txr-fbb35f10c305128e865f7c16e21f61ea6e62083e.tar.bz2 txr-fbb35f10c305128e865f7c16e21f61ea6e62083e.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.
Diffstat (limited to 'linenoise')
-rw-r--r-- | linenoise/linenoise.c | 7 |
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); } |