| #include <errno.h> |
| #include <signal.h> |
| #include <limits.h> |
| #include <stddef.h> |
| #include <stdlib.h> |
| #include <unistd.h> |
| #include <sys/types.h> |
| #include <windows.h> |
| |
| #define SHELL_PATH L"/Windows/command.exe" /* Path of the shell. */ |
| #define SHELL_OPTION L"/c " |
| |
| //#define SHELL_PATH L"/usr/bin/ash.exe" |
| //#define SHELL_PATH L"/usr/bin/ash" |
| //#define SHELL_PATH L"/usr/bin/ush" |
| //#define SHELL_PATH L"/bin/ush" |
| //#define SHELL_PATH L"/bin/sh" |
| //#define SHELL_OPTION L"-c " |
| |
| /* Execute LINE as a shell command, returning its status. */ |
| static int do_system(const char *line) { |
| unsigned long int result; |
| PROCESS_INFORMATION pi; |
| |
| //wchar_t wline[PATH_MAX]; |
| //mbstowcs(wline, line, PATH_MAX); |
| |
| wchar_t command_line[PATH_MAX] = SHELL_OPTION; |
| //wcscat(args, wline); |
| mbstowcs(command_line + (sizeof SHELL_OPTION / sizeof(wchar_t) - 1), line, PATH_MAX); |
| |
| if(!CreateProcessW(SHELL_PATH, command_line, NULL, NULL, 0, 0, NULL, NULL, NULL, &pi)) return 127; |
| WaitForSingleObject(pi.hProcess, INFINITE); |
| GetExitCodeProcess(pi.hProcess, &result); |
| CloseHandle(pi.hProcess); |
| CloseHandle(pi.hThread); |
| return result; |
| } |
| |
| int system(const char *line) { |
| if(!line) return do_system("exit") == 0; |
| return do_system(line); |
| } |