ladybird/Userland/Utilities/mkfifo.cpp

35 lines
826 B
C++
Raw Normal View History

2020-07-17 01:35:50 +03:00
/*
* Copyright (c) 2020, Peter Elliott <pelliott@serenityos.org>
2020-07-17 01:35:50 +03:00
*
* SPDX-License-Identifier: BSD-2-Clause
2020-07-17 01:35:50 +03:00
*/
#include <LibCore/ArgsParser.h>
2022-01-14 12:14:26 +03:00
#include <LibCore/System.h>
#include <LibMain/Main.h>
2020-07-17 01:35:50 +03:00
#include <sys/stat.h>
2022-01-14 12:14:26 +03:00
ErrorOr<int> serenity_main(Main::Arguments arguments)
2020-07-17 01:35:50 +03:00
{
2022-01-14 12:14:26 +03:00
TRY(Core::System::pledge("stdio dpath"));
2020-07-17 01:35:50 +03:00
mode_t mode = 0666;
2022-01-14 12:14:26 +03:00
Vector<StringView> paths;
2020-07-17 01:35:50 +03:00
Core::ArgsParser args_parser;
// FIXME: add -m for file modes
args_parser.add_positional_argument(paths, "Paths of FIFOs to create", "paths");
2022-01-14 12:14:26 +03:00
args_parser.parse(arguments);
2020-07-17 01:35:50 +03:00
int exit_code = 0;
for (auto path : paths) {
2022-01-14 12:14:26 +03:00
auto error_or_void = Core::System::mkfifo(path, mode);
if (error_or_void.is_error()) {
2020-07-17 01:35:50 +03:00
perror("mkfifo");
exit_code = 1;
}
}
return exit_code;
}