LibLine: Don't use fdopen() for stream in edit_in_external_editor()

We would have to fclose() it to be clean and nice, but that would close
the fd; instead just duplicate it and write through that, this makes it
actually write to the file.
This commit is contained in:
Ali Mohammad Pur 2022-04-11 04:24:06 +04:30 committed by Ali Mohammad Pur
parent 35cb5ea47c
commit 6aceec4535
Notes: sideshowbarker 2024-07-17 11:42:32 +09:00

View file

@ -529,14 +529,8 @@ void Editor::edit_in_external_editor()
}
{
auto* fp = fdopen(fd, "rw");
if (!fp) {
perror("fdopen");
return;
}
OutputFileStream stream { fp };
auto write_fd = dup(fd);
OutputFileStream stream { write_fd };
StringBuilder builder;
builder.append(Utf32View { m_buffer.data(), m_buffer.size() });
auto bytes = builder.string_view().bytes();
@ -544,6 +538,7 @@ void Editor::edit_in_external_editor()
auto nwritten = stream.write(bytes);
bytes = bytes.slice(nwritten);
}
lseek(fd, 0, SEEK_SET);
}
ScopeGuard remove_temp_file_guard {