mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
xargs: Port to LibMain
This commit is contained in:
parent
f705f57d9a
commit
d4748c608c
Notes:
sideshowbarker
2024-07-17 21:43:45 +09:00
Author: https://github.com/mjz19910 Commit: https://github.com/SerenityOS/serenity/commit/d4748c608cb Pull-request: https://github.com/SerenityOS/serenity/pull/11607 Reviewed-by: https://github.com/bgianfo
2 changed files with 6 additions and 11 deletions
|
@ -165,4 +165,5 @@ target_link_libraries(wasm LibWasm LibLine)
|
||||||
target_link_libraries(whoami LibMain)
|
target_link_libraries(whoami LibMain)
|
||||||
target_link_libraries(watch LibMain)
|
target_link_libraries(watch LibMain)
|
||||||
target_link_libraries(wsctl LibGUI)
|
target_link_libraries(wsctl LibGUI)
|
||||||
|
target_link_libraries(xargs LibMain)
|
||||||
target_link_libraries(yes LibMain)
|
target_link_libraries(yes LibMain)
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -37,12 +38,9 @@ private:
|
||||||
Vector<Vector<StringView>> m_all_parts;
|
Vector<Vector<StringView>> m_all_parts;
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
ErrorOr<int> serenity_main(Main::Arguments main_arguments)
|
||||||
{
|
{
|
||||||
if (pledge("stdio rpath proc exec", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio rpath proc exec", nullptr));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* placeholder = nullptr;
|
const char* placeholder = nullptr;
|
||||||
bool split_with_nulls = false;
|
bool split_with_nulls = false;
|
||||||
|
@ -64,7 +62,7 @@ int main(int argc, char** argv)
|
||||||
args_parser.add_option(max_lines_for_one_command, "Use at most max-lines lines to create a command", "line-limit", 'L', "max-lines");
|
args_parser.add_option(max_lines_for_one_command, "Use at most max-lines lines to create a command", "line-limit", 'L', "max-lines");
|
||||||
args_parser.add_option(max_bytes_for_one_command, "Use at most max-chars characters to create a command", "char-limit", 's', "max-chars");
|
args_parser.add_option(max_bytes_for_one_command, "Use at most max-chars characters to create a command", "char-limit", 's', "max-chars");
|
||||||
args_parser.add_positional_argument(arguments, "Command and any initial arguments for it", "command", Core::ArgsParser::Required::No);
|
args_parser.add_positional_argument(arguments, "Command and any initial arguments for it", "command", Core::ArgsParser::Required::No);
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(main_arguments);
|
||||||
|
|
||||||
size_t max_bytes = min(ARG_MAX, max_bytes_for_one_command);
|
size_t max_bytes = min(ARG_MAX, max_bytes_for_one_command);
|
||||||
size_t max_lines = max(max_lines_for_one_command, 0);
|
size_t max_lines = max(max_lines_for_one_command, 0);
|
||||||
|
@ -105,11 +103,7 @@ int main(int argc, char** argv)
|
||||||
int devnull_fd = 0;
|
int devnull_fd = 0;
|
||||||
|
|
||||||
if (is_stdin) {
|
if (is_stdin) {
|
||||||
devnull_fd = open("/dev/null", O_RDONLY | O_CLOEXEC);
|
devnull_fd = TRY(Core::System::open("/dev/null", O_RDONLY | O_CLOEXEC));
|
||||||
if (devnull_fd < 0) {
|
|
||||||
perror("open");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t total_command_length = 0;
|
size_t total_command_length = 0;
|
||||||
|
|
Loading…
Reference in a new issue