diff --git a/programs/develop/ktcc/trunk/libc.obj/include/stdlib.h b/programs/develop/ktcc/trunk/libc.obj/include/stdlib.h index dd9438e74..385572a32 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/stdlib.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/stdlib.h @@ -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 diff --git a/programs/develop/ktcc/trunk/libc.obj/source/libc.c b/programs/develop/ktcc/trunk/libc.obj/source/libc.c index 1c352739f..08bc1a6ae 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/libc.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/libc.c @@ -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 }, diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/system.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/system.c new file mode 100644 index 000000000..c20e0492a --- /dev/null +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/system.c @@ -0,0 +1,52 @@ +#include +#include +#include + +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; +}