diff options
author | Rummskartoffel <Rummskartoffel@protonmail.com> | 2022-01-08 13:03:22 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-08 15:29:38 +0100 |
commit | 748218d5d038ff53f4e9250fd2e58d6f202da8c0 (patch) | |
tree | d3e55f172f9cd3ada0cf04c679d7f511693411ec /Userland/Utilities | |
parent | 69445f3dcb3dc763135016db49ac8cde28f80f7d (diff) | |
download | serenity-748218d5d038ff53f4e9250fd2e58d6f202da8c0.zip |
gzip: Port to LibMain
Diffstat (limited to 'Userland/Utilities')
-rw-r--r-- | Userland/Utilities/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Userland/Utilities/gzip.cpp | 19 |
2 files changed, 7 insertions, 14 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index 7ca285a0d0..04d38f7279 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -102,7 +102,7 @@ target_link_libraries(grep LibRegex) target_link_libraries(gron LibMain) target_link_libraries(groups LibMain) target_link_libraries(gunzip LibCompress) -target_link_libraries(gzip LibCompress) +target_link_libraries(gzip LibCompress LibMain) target_link_libraries(id LibMain) target_link_libraries(ini LibMain) target_link_libraries(jp LibMain) diff --git a/Userland/Utilities/gzip.cpp b/Userland/Utilities/gzip.cpp index 18cefb442a..e55379ba18 100644 --- a/Userland/Utilities/gzip.cpp +++ b/Userland/Utilities/gzip.cpp @@ -8,9 +8,11 @@ #include <LibCore/ArgsParser.h> #include <LibCore/FileStream.h> #include <LibCore/MappedFile.h> +#include <LibCore/System.h> +#include <LibMain/Main.h> #include <unistd.h> -int main(int argc, char** argv) +ErrorOr<int> serenity_main(Main::Arguments arguments) { Vector<StringView> filenames; bool keep_input_files { false }; @@ -22,7 +24,7 @@ int main(int argc, char** argv) args_parser.add_option(write_to_stdout, "Write to stdout, keep original files unchanged", "stdout", 'c'); args_parser.add_option(decompress, "Decompress", "decompress", 'd'); args_parser.add_positional_argument(filenames, "Files", "FILES"); - args_parser.parse(argc, argv); + args_parser.parse(arguments); if (write_to_stdout) keep_input_files = true; @@ -41,12 +43,7 @@ int main(int argc, char** argv) // We map the whole file instead of streaming to reduce size overhead (gzip header) and increase the deflate block size (better compression) // TODO: automatically fallback to buffered streaming for very large files - auto file_or_error = Core::MappedFile::map(input_filename); - if (file_or_error.is_error()) { - warnln("Failed opening input file for reading: {}", file_or_error.error()); - return 1; - } - auto file = file_or_error.value(); + auto file = TRY(Core::MappedFile::map(input_filename)); AK::Optional<ByteBuffer> output_bytes; if (decompress) { @@ -78,11 +75,7 @@ int main(int argc, char** argv) } if (!keep_input_files) { - const auto retval = unlink(String(input_filename).characters()); - if (retval != 0) { - warnln("Failed removing input file"); - return 1; - } + TRY(Core::System::unlink(input_filename)); } } return 0; |