mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 23:37:43 +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
1 changed files with 3 additions and 8 deletions
|
@ -529,14 +529,8 @@ void Editor::edit_in_external_editor()
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto* fp = fdopen(fd, "rw");
|
auto write_fd = dup(fd);
|
||||||
if (!fp) {
|
OutputFileStream stream { write_fd };
|
||||||
perror("fdopen");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
OutputFileStream stream { fp };
|
|
||||||
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append(Utf32View { m_buffer.data(), m_buffer.size() });
|
builder.append(Utf32View { m_buffer.data(), m_buffer.size() });
|
||||||
auto bytes = builder.string_view().bytes();
|
auto bytes = builder.string_view().bytes();
|
||||||
|
@ -544,6 +538,7 @@ void Editor::edit_in_external_editor()
|
||||||
auto nwritten = stream.write(bytes);
|
auto nwritten = stream.write(bytes);
|
||||||
bytes = bytes.slice(nwritten);
|
bytes = bytes.slice(nwritten);
|
||||||
}
|
}
|
||||||
|
lseek(fd, 0, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopeGuard remove_temp_file_guard {
|
ScopeGuard remove_temp_file_guard {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue