libc.obj: add system
Some checks failed
Build system / Build (pull_request) Failing after 2s
Build system / Check kernel codestyle (pull_request) Successful in 1m20s

This commit is contained in:
2026-01-19 21:21:42 +05:00
parent 16b520dd67
commit 2818bf25e2
3 changed files with 59 additions and 4 deletions

View File

@@ -11,9 +11,8 @@
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define EXIT_SUCCESS 0 // Successful execution of a program
#define EXIT_FAILURE 1 // Unsuccessful execution of a program
#define EXIT_FAILURE 1 // Unsuccessful execution of a program
typedef struct {
int quot;
@@ -60,8 +59,8 @@ DLLAPI void _exit(int status);
DLLAPI void abort();
DLLAPI void exit(int status);
DLLAPI int atexit( void (*func)(void) );
DLLAPI int atexit(void (*func)(void));
DLLAPI void srand(unsigned s);
DLLAPI int rand(void);
@@ -80,4 +79,6 @@ DLLAPI int abs(int);
DLLAPI long labs(long);
DLLAPI long long llabs(long long);
DLLAPI int system(const char* command);
#endif

View File

@@ -103,6 +103,7 @@
#include "stdlib/strtod.c"
#include "stdlib/strtol.c"
#include "stdlib/abort.c"
#include "stdlib/system.c"
#include "math/acosh.c"
#include "math/asinh.c"
@@ -183,6 +184,7 @@ ksys_dll_t EXPORTS[] = {
{ "realloc", &realloc },
{ "strtol", &strtol },
{ "abort", &abort},
{ "system", &system },
{ "srand", &srand },
{ "rand", &rand },
{ "qsort", &qsort },

View File

@@ -0,0 +1,52 @@
#include <stdlib.h>
#include <string.h>
#include <sys/ksys.h>
static int __system_parse_command(const char* command, char** path, char** args)
{
if (command == NULL || path == NULL || args == NULL) {
return -1;
}
const char* space = strchr(command, ' ');
if (space == NULL) {
*path = strdup(command);
if (*path == NULL) {
return -1;
}
*args = NULL;
return 0;
}
size_t path_len = space - command;
*path = (char*)malloc(path_len + 1);
if (*path == NULL) {
return -1;
}
strncpy(*path, command, path_len);
(*path)[path_len] = '\0';
size_t args_len = strlen(space) + 1;
*args = (char*)malloc(args_len + 1);
if (*args == NULL) {
free(*path);
return -1;
}
strcpy(*args, space);
return 0;
}
int system(const char* command)
{
if (command == NULL || *command == '\0')
return 1;
char* cmd;
char* args;
int ret = _ksys_exec(cmd, args);
free(cmd);
free(args);
return ret;
}