From 620af69d888bc5d0fa2179f06423aa1fb290b11b Mon Sep 17 00:00:00 2001 From: Robert Wilhelm Date: Thu, 27 May 2010 18:45:06 +0200 Subject: [PATCH] msvcrt: Support system(NULL). --- dlls/msvcrt/process.c | 19 ++++++++++++++++++- dlls/msvcrt/tests/environ.c | 11 +++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/dlls/msvcrt/process.c b/dlls/msvcrt/process.c index 564c10052db..b4c39c1de6c 100644 --- a/dlls/msvcrt/process.c +++ b/dlls/msvcrt/process.c @@ -1168,7 +1168,21 @@ int CDECL _wsystem(const MSVCRT_wchar_t* cmd) unsigned int len; static const MSVCRT_wchar_t flag[] = {' ','/','c',' ',0}; - if (!(comspec = msvcrt_get_comspec())) return -1; + comspec = msvcrt_get_comspec(); + + if (cmd == NULL) + { + if (comspec == NULL) + { + *MSVCRT__errno() = MSVCRT_ENOENT; + return 0; + } + return 1; + } + + if ( comspec == NULL) + return -1; + len = strlenW(comspec) + strlenW(flag) + strlenW(cmd) + 1; if (!(fullcmd = HeapAlloc(GetProcessHeap(), 0, len * sizeof(MSVCRT_wchar_t)))) @@ -1195,6 +1209,9 @@ int CDECL MSVCRT_system(const char* cmd) int res = -1; MSVCRT_wchar_t *cmdW; + if (cmd == NULL) + return _wsystem(NULL); + if ((cmdW = msvcrt_wstrdupa(cmd))) { res = _wsystem(cmdW); diff --git a/dlls/msvcrt/tests/environ.c b/dlls/msvcrt/tests/environ.c index 6175e14af69..336238ce13f 100644 --- a/dlls/msvcrt/tests/environ.c +++ b/dlls/msvcrt/tests/environ.c @@ -42,6 +42,15 @@ static const char *a_very_long_env_string = "/usr/lib/mingw32/3.4.2/;" "/usr/lib/"; +static void test_system(void) +{ + int ret = system(NULL); + ok(ret == 1, "Expected system to return 1, got %d\n", ret); + + ret = system("echo OK"); + ok(ret == 0, "Expected system to return 0, got %d\n", ret); +} + START_TEST(environ) { ok( _putenv("cat=") == 0, "_putenv failed on deletion of nonexistent environment variable\n" ); @@ -54,4 +63,6 @@ START_TEST(environ) ok( _putenv(a_very_long_env_string) == 0, "_putenv failed for long environment string\n"); ok( getenv("nonexistent") == NULL, "getenv should fail with nonexistent var name\n" ); + + test_system(); }