mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 10:18:15 +09:00
LibCore+ImageViewer: Add unlink() wrapper, use it
This commit is contained in:
parent
080c3164c7
commit
9a38d1de07
Notes:
sideshowbarker
2024-07-17 21:32:44 +09:00
Author: https://github.com/juniorrantila
Commit: 9a38d1de07
Pull-request: https://github.com/SerenityOS/serenity/pull/11492
3 changed files with 20 additions and 3 deletions
|
@ -131,10 +131,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
if (msgbox_result == GUI::MessageBox::ExecCancel)
|
if (msgbox_result == GUI::MessageBox::ExecCancel)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (unlink(widget.path().characters()) < 0) {
|
auto unlinked_or_error = Core::System::unlink(widget.path());
|
||||||
int saved_errno = errno;
|
if (unlinked_or_error.is_error()) {
|
||||||
GUI::MessageBox::show(window,
|
GUI::MessageBox::show(window,
|
||||||
String::formatted("unlink({}) failed: {}", path, strerror(saved_errno)),
|
String::formatted("unlink({}) failed: {}", path, unlinked_or_error.error()),
|
||||||
"Delete failed",
|
"Delete failed",
|
||||||
GUI::MessageBox::Type::Error);
|
GUI::MessageBox::Type::Error);
|
||||||
|
|
||||||
|
|
|
@ -644,6 +644,22 @@ ErrorOr<void> rename(StringView old_path, StringView new_path)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> unlink(StringView path)
|
||||||
|
{
|
||||||
|
if (path.is_null())
|
||||||
|
return Error::from_errno(EFAULT);
|
||||||
|
|
||||||
|
#ifdef __serenity__
|
||||||
|
int rc = syscall(SC_unlink, path.characters_without_null_termination(), path.length());
|
||||||
|
HANDLE_SYSCALL_RETURN_VALUE("unlink"sv, rc, {});
|
||||||
|
#else
|
||||||
|
String path_string = path;
|
||||||
|
if (::unlink(path_string.characters()) < 0)
|
||||||
|
return Error::from_syscall("unlink"sv, -errno);
|
||||||
|
return {};
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<void> utime(StringView path, Optional<struct utimbuf> maybe_buf)
|
ErrorOr<void> utime(StringView path, Optional<struct utimbuf> maybe_buf)
|
||||||
{
|
{
|
||||||
if (path.is_null())
|
if (path.is_null())
|
||||||
|
|
|
@ -98,6 +98,7 @@ ErrorOr<pid_t> fork();
|
||||||
ErrorOr<int> mkstemp(Span<char> pattern);
|
ErrorOr<int> mkstemp(Span<char> pattern);
|
||||||
ErrorOr<void> fchmod(int fd, mode_t mode);
|
ErrorOr<void> fchmod(int fd, mode_t mode);
|
||||||
ErrorOr<void> rename(StringView old_path, StringView new_path);
|
ErrorOr<void> rename(StringView old_path, StringView new_path);
|
||||||
|
ErrorOr<void> unlink(StringView path);
|
||||||
ErrorOr<void> utime(StringView path, Optional<struct utimbuf>);
|
ErrorOr<void> utime(StringView path, Optional<struct utimbuf>);
|
||||||
ErrorOr<struct utsname> uname();
|
ErrorOr<struct utsname> uname();
|
||||||
ErrorOr<Array<int, 2>> pipe2(int flags);
|
ErrorOr<Array<int, 2>> pipe2(int flags);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue