From: Eric Pouech epouech@codeweavers.com
Signed-off-by: Eric Pouech epouech@codeweavers.com --- programs/cmd/directory.c | 23 ++++++++++++++--------- programs/cmd/tests/test_builtins.cmd.exp | 6 +++--- programs/cmd/wcmd.h | 2 +- programs/cmd/wcmdmain.c | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/programs/cmd/directory.c b/programs/cmd/directory.c index 72542538d5b..fdcae9f6a94 100644 --- a/programs/cmd/directory.c +++ b/programs/cmd/directory.c @@ -631,7 +631,7 @@ static void init_time_format(void) * */
-void WCMD_directory (WCHAR *args) +RETURN_CODE WCMD_directory(WCHAR *args) { WCHAR path[MAX_PATH], cwd[MAX_PATH]; DWORD status; @@ -649,6 +649,7 @@ void WCMD_directory (WCHAR *args) WCHAR dir[MAX_PATH]; WCHAR fname[MAX_PATH]; WCHAR ext[MAX_PATH]; + unsigned num_empty = 0, num_with_data = 0;
errorlevel = NO_ERROR;
@@ -736,8 +737,7 @@ void WCMD_directory (WCHAR *args) } else { SetLastError(ERROR_INVALID_PARAMETER); WCMD_print_error(); - errorlevel = ERROR_INVALID_FUNCTION; - return; + return errorlevel = ERROR_INVALID_FUNCTION; } break; case 'O': p = p + 1; @@ -756,8 +756,7 @@ void WCMD_directory (WCHAR *args) default: SetLastError(ERROR_INVALID_PARAMETER); WCMD_print_error(); - errorlevel = ERROR_INVALID_FUNCTION; - return; + return errorlevel = ERROR_INVALID_FUNCTION; } p++; } @@ -787,8 +786,7 @@ void WCMD_directory (WCHAR *args) default: SetLastError(ERROR_INVALID_PARAMETER); WCMD_print_error(); - errorlevel = ERROR_INVALID_FUNCTION; - return; + return errorlevel = ERROR_INVALID_FUNCTION; }
/* Keep running list of bits we care about */ @@ -806,8 +804,7 @@ void WCMD_directory (WCHAR *args) default: SetLastError(ERROR_INVALID_PARAMETER); WCMD_print_error(); - errorlevel = ERROR_INVALID_FUNCTION; - return; + return errorlevel = ERROR_INVALID_FUNCTION; } p = p + 1; } @@ -957,6 +954,10 @@ void WCMD_directory (WCHAR *args) errorlevel = NO_ERROR; prevEntry = thisEntry; thisEntry = WCMD_list_directory (thisEntry, 0); + if (errorlevel) + num_empty++; + else + num_with_data++; }
/* Trailer Information */ @@ -964,6 +965,8 @@ void WCMD_directory (WCHAR *args) WCMD_dir_trailer(prevEntry->dirName); }
+ if (num_empty && !num_with_data) + errorlevel = ERROR_INVALID_FUNCTION; exit: if (paged_mode) WCMD_leave_paged_mode();
@@ -975,4 +978,6 @@ exit: free(prevEntry->fileName); free(prevEntry); } + + return errorlevel; } diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp index 0397311cf85..8d5926580d9 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -514,11 +514,11 @@ SUCCESS 0 @todo_wine@SUCCESS 666 @todo_wine@FAILURE 1 @todo_wine@--- success/failure for DIR command -@todo_wine@FAILURE 1 -@todo_wine@FAILURE 1 +FAILURE 1 +FAILURE 1 SUCCESS 0 SUCCESS 0 -@todo_wine@FAILURE 1 +FAILURE 1 SUCCESS 0 @todo_wine@--- ------------ Testing 'set' ------------ diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h index f538d3069bb..0ca14e9f2ac 100644 --- a/programs/cmd/wcmd.h +++ b/programs/cmd/wcmd.h @@ -169,7 +169,7 @@ void WCMD_color (void); RETURN_CODE WCMD_copy(WCHAR *); RETURN_CODE WCMD_create_dir(WCHAR *); RETURN_CODE WCMD_delete(WCHAR *); -void WCMD_directory (WCHAR *); +RETURN_CODE WCMD_directory(WCHAR *); RETURN_CODE WCMD_echo(const WCHAR *); void WCMD_endlocal (void); void WCMD_enter_paged_mode(const WCHAR *); diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index 2228593157e..dc7da5979be 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -1833,7 +1833,7 @@ static RETURN_CODE execute_single_command(const WCHAR *command) return_code = WCMD_delete(parms_start); break; case WCMD_DIR: - WCMD_directory (parms_start); + return_code = WCMD_directory(parms_start); break; case WCMD_ECHO: return_code = WCMD_echo(&whichcmd[count]);