Signed-off-by: Francois Gouget fgouget@codeweavers.com --- programs/cmd/builtins.c | 13 +++++++++++-- programs/cmd/tests/test_builtins.cmd.exp | 10 +++++----- 2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index d3d62d7dc56..7ece4b52a9e 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -2823,8 +2823,17 @@ int evaluate_if_condition(WCHAR *p, WCHAR **command, int *test, int *negate) WCMD_parameter(p, 2+(*negate), command, FALSE, FALSE); } else if (!lstrcmpiW(condition, L"defined")) { - *test = (GetEnvironmentVariableW(WCMD_parameter(p, 1+(*negate), NULL, FALSE, FALSE), - NULL, 0) > 0); + const WCHAR* name = WCMD_parameter(p, 1+(*negate), NULL, FALSE, FALSE); + if (lstrcmpiW(name, L"cd") == 0 || + lstrcmpiW(name, L"date") == 0 || + lstrcmpiW(name, L"errorlevel") == 0 || + lstrcmpiW(name, L"random") == 0 || + lstrcmpiW(name, L"time") == 0) { + *test = 1; + } + else { + *test = (GetEnvironmentVariableW(name, NULL, 0) > 0); + } WCMD_parameter(p, 2+(*negate), command, FALSE, FALSE); } else { /* comparison operation */ diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp index 0d55d6b8630..0cfbaebfd85 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -1216,18 +1216,18 @@ WINE_foo correctly 8@or_broken@ERROR: WINE_foo incorrectly 4 [8] WINE_foo correctly 6@or_broken@ERROR: WINE_foo incorrectly 5 [6] WINE_bar correctly 6@or_broken@ERROR: WINE_bar incorrectly 5 [6] --- Magic environment variables -@todo_wine@Has %cd% +Has %cd% CD value @pwd@@or_broken@CD value@space@ -@todo_wine@Has %date% +Has %date% Good %date% Match -@todo_wine@Has %errorlevel% -@todo_wine@Has %time% +Has %errorlevel% +Has %time% %time% has seconds %time% has 1/100s End of %time% Match -@todo_wine@Has %random% +Has %random% %random% looks random --- for /F ------ string argument