|
3 | 3 | #include "anyfin/startup.hpp" |
4 | 4 | #include "anyfin/console.hpp" |
5 | 5 | #include "anyfin/platform.hpp" |
| 6 | +#include "anyfin/commands.hpp" |
6 | 7 |
|
7 | 8 | #include "cbuild.hpp" |
8 | 9 | #include "cbuild_api.hpp" |
@@ -526,3 +527,22 @@ CBUILD_EXPERIMENTAL_API const char * find_executable (Project *project, const ch |
526 | 527 | auto [system_error, path] = find_executable(project->arena, String(name, get_string_length(name))); |
527 | 528 | return (system_error || path.is_none()) ? nullptr : path.value.value; |
528 | 529 | } |
| 530 | + |
| 531 | +CBUILD_EXPERIMENTAL_API int run_system_command (Project *project, const char *command_str, char *buffer, unsigned int buffer_size, unsigned int *written_size) CBUILD_NO_EXCEPT { |
| 532 | + auto command = String(command_str, get_string_length(command_str)); |
| 533 | + |
| 534 | + auto [system_error, status] = run_system_command(project->arena, command); |
| 535 | + if (system_error) panic("Command '%' execution failed due to a system error: %\n", command, system_error.value); |
| 536 | + |
| 537 | + if (status.output.length == 0 || !buffer || !buffer_size) { |
| 538 | + if (written_size) *written_size = 0; |
| 539 | + return status.status_code; |
| 540 | + } |
| 541 | + |
| 542 | + auto bytes_to_copy = (status.output.length < buffer_size) ? status.output.length : buffer_size; |
| 543 | + copy_memory(buffer, status.output.value, bytes_to_copy); |
| 544 | + |
| 545 | + if (written_size) *written_size = bytes_to_copy; |
| 546 | + |
| 547 | + return status.status_code; |
| 548 | +} |
0 commit comments