mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
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:
parent
35cb5ea47c
commit
6aceec4535
Notes:
sideshowbarker
2024-07-17 11:42:32 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/6aceec4535 Pull-request: https://github.com/SerenityOS/serenity/pull/13686
1 changed files with 3 additions and 8 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue