diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index b02bfbbacf..5398f7196f 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -136,6 +136,7 @@ target_link_libraries(test-fuzz LibCore LibGemini LibGfx LibHTTP LibIPC LibJS Li target_link_libraries(test-imap LibIMAP) target_link_libraries(test-pthread LibThreading) target_link_libraries(top LibMain) +target_link_libraries(touch LibMain) target_link_libraries(truncate LibMain) target_link_libraries(tt LibPthread) target_link_libraries(unzip LibArchive LibCompress) diff --git a/Userland/Utilities/touch.cpp b/Userland/Utilities/touch.cpp index 5b5ba74fc1..6ad681136f 100644 --- a/Userland/Utilities/touch.cpp +++ b/Userland/Utilities/touch.cpp @@ -1,10 +1,12 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include +#include +#include #include #include #include @@ -28,12 +30,9 @@ static bool file_exists(const char* path) exit(1); } -int main(int argc, char** argv) +ErrorOr serenity_main(Main::Arguments arguments) { - if (pledge("stdio rpath cpath fattr", nullptr)) { - perror("pledge"); - return 1; - } + TRY(Core::System::pledge("stdio rpath cpath fattr")); Vector paths; @@ -41,24 +40,15 @@ int main(int argc, char** argv) args_parser.set_general_help("Create a file, or update its mtime (time of last modification)."); args_parser.add_ignored(nullptr, 'f'); args_parser.add_positional_argument(paths, "Files to touch", "path", Core::ArgsParser::Required::Yes); - args_parser.parse(argc, argv); + args_parser.parse(arguments); for (auto path : paths) { if (file_exists(path)) { - int rc = utime(path, nullptr); - if (rc < 0) - perror("utime"); + if (auto result = Core::System::utime(path, {}); result.is_error()) + warnln("{}", result.release_error()); } else { - int fd = open(path, O_CREAT, 0100644); - if (fd < 0) { - perror("open"); - return 1; - } - int rc = close(fd); - if (rc < 0) { - perror("close"); - return 1; - } + int fd = TRY(Core::System::open(path, O_CREAT, 0100644)); + TRY(Core::System::close(fd)); } } return 0;