/* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, Kenneth Myhra * Copyright (c) 2021, Xavier Defrang * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include #include #include #include #include ErrorOr serenity_main(Main::Arguments arguments) { TRY(Core::System::pledge("stdio rpath fattr")); if (arguments.strings.size() < 3) { warnln("usage: chmod "); warnln(" chmod [[ugoa][+-=][rwx...],...] "); return 1; } auto mask = TRY(Core::FilePermissionsMask::parse(arguments.strings[1])); for (size_t i = 2; i < arguments.strings.size(); ++i) { auto current_access = TRY(Core::System::stat(arguments.strings[i])); TRY(Core::System::chmod(arguments.strings[i], mask.apply(current_access.st_mode))); } return 0; }