From 6aceec45357f8e253bc169f1ed961fc26038a3da Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Mon, 11 Apr 2022 04:24:06 +0430 Subject: [PATCH] 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. --- Userland/Libraries/LibLine/InternalFunctions.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibLine/InternalFunctions.cpp b/Userland/Libraries/LibLine/InternalFunctions.cpp index 7bfec19a9c..d6edd10494 100644 --- a/Userland/Libraries/LibLine/InternalFunctions.cpp +++ b/Userland/Libraries/LibLine/InternalFunctions.cpp @@ -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 {