mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 14:25:08 +00:00
LibGUI: Use a ScopeGuard to close the fd in TextEditor::write_to_file()
This commit is contained in:
parent
015c5e61a8
commit
a048f46be5
1 changed files with 2 additions and 3 deletions
|
@ -1058,6 +1058,8 @@ bool TextEditor::write_to_file(const String& path)
|
|||
return false;
|
||||
}
|
||||
|
||||
ScopeGuard fd_guard = [fd] { close(fd); };
|
||||
|
||||
// Compute the final file size and ftruncate() to make writing fast.
|
||||
// FIXME: Remove this once the kernel is smart enough to do this instead.
|
||||
off_t file_size = 0;
|
||||
|
@ -1078,7 +1080,6 @@ bool TextEditor::write_to_file(const String& path)
|
|||
ssize_t nwritten = write(fd, line_as_utf8.characters(), line_as_utf8.length());
|
||||
if (nwritten < 0) {
|
||||
perror("write");
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1087,13 +1088,11 @@ bool TextEditor::write_to_file(const String& path)
|
|||
ssize_t nwritten = write(fd, &ch, 1);
|
||||
if (nwritten != 1) {
|
||||
perror("write");
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue