From 87f0293657591c2bed80bcf36801a8a2c889b3fc Mon Sep 17 00:00:00 2001 From: Jason Edmeades Date: Tue, 13 Mar 2007 00:11:31 +0000 Subject: [PATCH] cmd.exe: Make SET have correct errorlevel. --- programs/cmd/builtins.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 02004ae1a93..4efe5805388 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -1278,6 +1278,7 @@ void WCMD_setshow_env (char *s) { char *p; int status; + errorlevel = 0; if (param1[0] == 0x00 && quals[0] == 0x00) { env = GetEnvironmentStrings (); WCMD_setshow_sortenv( env, NULL ); @@ -1314,11 +1315,13 @@ void WCMD_setshow_env (char *s) { } } else { + DWORD gle; p = strchr (s, '='); if (p == NULL) { env = GetEnvironmentStrings (); if (WCMD_setshow_sortenv( env, s ) == 0) { WCMD_output ("Environment variable %s not defined\n", s); + errorlevel = 1; } return; } @@ -1326,7 +1329,10 @@ void WCMD_setshow_env (char *s) { if (strlen(p) == 0) p = NULL; status = SetEnvironmentVariable (s, p); - if ((!status) & (GetLastError() != ERROR_ENVVAR_NOT_FOUND)) WCMD_print_error(); + gle = GetLastError(); + if ((!status) & (gle == ERROR_ENVVAR_NOT_FOUND)) { + errorlevel = 1; + } else if ((!status)) WCMD_print_error(); } }