ladybird/Userland/Utilities/mkfifo.cpp

43 lines
1.2 KiB
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>
#include <LibCore/FilePermissionsMask.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
ByteString mode_string;
mode_t mask_reference_mode = 0777;
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;
args_parser.add_option(mode_string, "Set FIFO permissions", "mode", 'm', "mode");
2020-07-17 01:35:50 +03:00
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
if (!mode_string.is_empty()) {
auto mask = TRY(Core::FilePermissionsMask::parse(mode_string));
mode = mask.apply(mask_reference_mode);
}
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()) {
warnln("mkfifo: Couldn't create fifo '{}': {}", path, error_or_void.error());
2020-07-17 01:35:50 +03:00
exit_code = 1;
}
}
return exit_code;
}