diff options
author | Kenneth Myhra <kennethmyhra@gmail.com> | 2022-01-14 17:23:48 +0100 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-01-24 14:01:58 +0330 |
commit | 3af7a5dd61be123d86bfa2ab2c9d586a6510e6a8 (patch) | |
tree | a4d9b8d1c097a00486baf3d8e6f0130b8aee464a /Userland/Utilities | |
parent | 9fe1ebebdcdc7af78606b359b45f34f5b87a0ca6 (diff) | |
download | serenity-3af7a5dd61be123d86bfa2ab2c9d586a6510e6a8.zip |
mknod: Port to LibMain
Diffstat (limited to 'Userland/Utilities')
-rw-r--r-- | Userland/Utilities/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Utilities/mknod.cpp | 36 |
2 files changed, 16 insertions, 21 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index 846f2c2f64..9486bbe9fa 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -129,6 +129,7 @@ target_link_libraries(markdown-check LibMarkdown) target_link_libraries(matroska LibVideo) target_link_libraries(md LibMarkdown) target_link_libraries(mkdir LibMain) +target_link_libraries(mknod LibMain) target_link_libraries(nc LibMain) target_link_libraries(netstat LibMain) target_link_libraries(notify LibGUI) diff --git a/Userland/Utilities/mknod.cpp b/Userland/Utilities/mknod.cpp index 6d9c8f8c1c..beeb3c5da9 100644 --- a/Userland/Utilities/mknod.cpp +++ b/Userland/Utilities/mknod.cpp @@ -5,11 +5,11 @@ */ #include <AK/Format.h> -#include <stdio.h> +#include <LibCore/System.h> +#include <LibMain/Main.h> #include <stdlib.h> #include <sys/stat.h> #include <sys/sysmacros.h> -#include <unistd.h> static int usage() { @@ -17,27 +17,24 @@ static int usage() return 1; } -int main(int argc, char** argv) +ErrorOr<int> serenity_main(Main::Arguments arguments) { - if (pledge("stdio dpath", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(Core::System::pledge("stdio dpath")); // FIXME: Add some kind of option for specifying the file permissions. - if (argc < 3) + if (arguments.strings.size() < 3) return usage(); - if (argv[2][0] == 'p') { - if (argc != 3) + if (arguments.strings[2].starts_with('p')) { + if (arguments.strings.size() != 3) return usage(); - } else if (argc != 5) { + } else if (arguments.strings.size() != 5) { return usage(); } - const char* name = argv[1]; + auto name = arguments.strings[1]; mode_t mode = 0666; - switch (argv[2][0]) { + switch (arguments.strings[2][0]) { case 'c': case 'u': mode |= S_IFCHR; @@ -54,15 +51,12 @@ int main(int argc, char** argv) int major = 0; int minor = 0; - if (argc == 5) { - major = atoi(argv[3]); - minor = atoi(argv[4]); + if (arguments.strings.size() == 5) { + major = atoi(arguments.argv[3]); + minor = atoi(arguments.argv[4]); } - int rc = mknod(name, mode, makedev(major, minor)); - if (rc < 0) { - perror("mknod"); - return 1; - } + TRY(Core::System::mknod(name, mode, makedev(major, minor))); + return 0; } |