blob: 0e633a1b68d8934096d3640f8d59fe289c864275 [file] [log] [blame] [raw]
/* A part of the Windows CE C Extra Library (celibc)
Copyright 2007-2015 PC GO Ld.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*/
#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);
#if _WCE >= 2
GetExitCodeProcess(pi.hProcess, &result);
#else
result = 0;
#endif
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return result;
}
int system(const char *line) {
if(!line) return do_system("exit") == 0;
return do_system(line);
}