mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
mknod: Port to LibMain
This commit is contained in:
parent
9fe1ebebdc
commit
3af7a5dd61
2 changed files with 16 additions and 21 deletions
|
@ -129,6 +129,7 @@ target_link_libraries(markdown-check LibMarkdown)
|
||||||
target_link_libraries(matroska LibVideo)
|
target_link_libraries(matroska LibVideo)
|
||||||
target_link_libraries(md LibMarkdown)
|
target_link_libraries(md LibMarkdown)
|
||||||
target_link_libraries(mkdir LibMain)
|
target_link_libraries(mkdir LibMain)
|
||||||
|
target_link_libraries(mknod LibMain)
|
||||||
target_link_libraries(nc LibMain)
|
target_link_libraries(nc LibMain)
|
||||||
target_link_libraries(netstat LibMain)
|
target_link_libraries(netstat LibMain)
|
||||||
target_link_libraries(notify LibGUI)
|
target_link_libraries(notify LibGUI)
|
||||||
|
|
|
@ -5,11 +5,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <stdio.h>
|
#include <LibCore/System.h>
|
||||||
|
#include <LibMain/Main.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/sysmacros.h>
|
#include <sys/sysmacros.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
static int usage()
|
static int usage()
|
||||||
{
|
{
|
||||||
|
@ -17,27 +17,24 @@ static int usage()
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
if (pledge("stdio dpath", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio dpath"));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: Add some kind of option for specifying the file permissions.
|
// FIXME: Add some kind of option for specifying the file permissions.
|
||||||
if (argc < 3)
|
if (arguments.strings.size() < 3)
|
||||||
return usage();
|
return usage();
|
||||||
|
|
||||||
if (argv[2][0] == 'p') {
|
if (arguments.strings[2].starts_with('p')) {
|
||||||
if (argc != 3)
|
if (arguments.strings.size() != 3)
|
||||||
return usage();
|
return usage();
|
||||||
} else if (argc != 5) {
|
} else if (arguments.strings.size() != 5) {
|
||||||
return usage();
|
return usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* name = argv[1];
|
auto name = arguments.strings[1];
|
||||||
mode_t mode = 0666;
|
mode_t mode = 0666;
|
||||||
switch (argv[2][0]) {
|
switch (arguments.strings[2][0]) {
|
||||||
case 'c':
|
case 'c':
|
||||||
case 'u':
|
case 'u':
|
||||||
mode |= S_IFCHR;
|
mode |= S_IFCHR;
|
||||||
|
@ -54,15 +51,12 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
int major = 0;
|
int major = 0;
|
||||||
int minor = 0;
|
int minor = 0;
|
||||||
if (argc == 5) {
|
if (arguments.strings.size() == 5) {
|
||||||
major = atoi(argv[3]);
|
major = atoi(arguments.argv[3]);
|
||||||
minor = atoi(argv[4]);
|
minor = atoi(arguments.argv[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
int rc = mknod(name, mode, makedev(major, minor));
|
TRY(Core::System::mknod(name, mode, makedev(major, minor)));
|
||||||
if (rc < 0) {
|
|
||||||
perror("mknod");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue