mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:42:44 +00:00 
			
		
		
		
	syscall: Port to LibMain
This commit is contained in:
		
							parent
							
								
									6deb032335
								
							
						
					
					
						commit
						61f2b7434f
					
				
					 2 changed files with 10 additions and 7 deletions
				
			
		|  | @ -166,6 +166,7 @@ target_link_libraries(stat LibMain) | ||||||
| target_link_libraries(strace LibMain) | target_link_libraries(strace LibMain) | ||||||
| target_link_libraries(su LibCrypt LibMain) | target_link_libraries(su LibCrypt LibMain) | ||||||
| target_link_libraries(sync LibMain) | target_link_libraries(sync LibMain) | ||||||
|  | target_link_libraries(syscall LibMain) | ||||||
| target_link_libraries(tac LibMain) | target_link_libraries(tac LibMain) | ||||||
| target_link_libraries(tail LibMain) | target_link_libraries(tail LibMain) | ||||||
| target_link_libraries(tar LibArchive LibCompress) | target_link_libraries(tar LibArchive LibCompress) | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| /*
 | /*
 | ||||||
|  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> |  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> | ||||||
|  |  * Copyright (c) 2022, Alex Major | ||||||
|  * |  * | ||||||
|  * SPDX-License-Identifier: BSD-2-Clause |  * SPDX-License-Identifier: BSD-2-Clause | ||||||
|  */ |  */ | ||||||
|  | @ -9,6 +10,7 @@ | ||||||
| #include <AK/Iterator.h> | #include <AK/Iterator.h> | ||||||
| #include <AK/Vector.h> | #include <AK/Vector.h> | ||||||
| #include <LibCore/ArgsParser.h> | #include <LibCore/ArgsParser.h> | ||||||
|  | #include <LibMain/Main.h> | ||||||
| #include <errno_codes.h> | #include <errno_codes.h> | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
|  | @ -34,11 +36,11 @@ struct AK::Formatter<Syscall::Function> : Formatter<StringView> { | ||||||
|     } |     } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| int main(int argc, char** argv) | ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
| { | { | ||||||
|     bool output_buffer = false; |     bool output_buffer = false; | ||||||
|     bool list_syscalls = false; |     bool list_syscalls = false; | ||||||
|     Vector<const char*> arguments; |     Vector<const char*> syscall_arguments; | ||||||
| 
 | 
 | ||||||
|     Core::ArgsParser args_parser; |     Core::ArgsParser args_parser; | ||||||
|     args_parser.set_general_help( |     args_parser.set_general_help( | ||||||
|  | @ -54,8 +56,8 @@ int main(int argc, char** argv) | ||||||
|         "Full example: syscall -o realpath [ /usr/share/man/man2/getgid.md 1024 buf 1024 ]"); |         "Full example: syscall -o realpath [ /usr/share/man/man2/getgid.md 1024 buf 1024 ]"); | ||||||
|     args_parser.add_option(list_syscalls, "List all existing syscalls, and exit", "list-syscalls", 'l'); |     args_parser.add_option(list_syscalls, "List all existing syscalls, and exit", "list-syscalls", 'l'); | ||||||
|     args_parser.add_option(output_buffer, "Output the contents of the buffer (beware of stray zero bytes!)", "output-buffer", 'o'); |     args_parser.add_option(output_buffer, "Output the contents of the buffer (beware of stray zero bytes!)", "output-buffer", 'o'); | ||||||
|     args_parser.add_positional_argument(arguments, "Syscall arguments; see general help.", "syscall-arguments", Core::ArgsParser::Required::No); |     args_parser.add_positional_argument(syscall_arguments, "Syscall arguments; see general help.", "syscall-arguments", Core::ArgsParser::Required::No); | ||||||
|     args_parser.parse(argc, argv); |     args_parser.parse(arguments); | ||||||
| 
 | 
 | ||||||
|     if (list_syscalls) { |     if (list_syscalls) { | ||||||
|         outln("syscall list:"); |         outln("syscall list:"); | ||||||
|  | @ -65,12 +67,12 @@ int main(int argc, char** argv) | ||||||
|         exit(0); |         exit(0); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (arguments.is_empty()) { |     if (syscall_arguments.is_empty()) { | ||||||
|         args_parser.print_usage(stderr, argv[0]); |         args_parser.print_usage(stderr, arguments.argv[0]); | ||||||
|         exit(1); |         exit(1); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     ArgIter iter = arguments.begin(); |     ArgIter iter = syscall_arguments.begin(); | ||||||
|     for (size_t i = 0; i < SC_NARG && !iter.is_end(); i++) { |     for (size_t i = 0; i < SC_NARG && !iter.is_end(); i++) { | ||||||
|         arg[i] = parse_from(iter); |         arg[i] = parse_from(iter); | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 alexmajor
						alexmajor