diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-04-11 04:24:06 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-04-18 19:53:10 +0430 |
commit | 6aceec45357f8e253bc169f1ed961fc26038a3da (patch) | |
tree | 7d2c09ad1ae4efe2fdb22710917c541f53051c56 /Userland/Libraries/LibLine | |
parent | 35cb5ea47ced471ae20d7dd87135ad3121e0c272 (diff) | |
download | serenity-6aceec45357f8e253bc169f1ed961fc26038a3da.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibLine')
-rw-r--r-- | Userland/Libraries/LibLine/InternalFunctions.cpp | 11 |
1 files 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 { |