Commit 3d3c5ab4 authored by Alexandre Julliard's avatar Alexandre Julliard

cmd: Add a helper function to check if a path ends with a backslash.

parent 9c5f2312
......@@ -798,12 +798,12 @@ void WCMD_copy(WCHAR * args) {
/* If parameter is a directory, ensure it ends in \ */
attributes = GetFileAttributesW(destname);
if ((destname[strlenW(destname) - 1] == '\\') ||
if (ends_with_backslash( destname ) ||
((attributes != INVALID_FILE_ATTRIBUTES) &&
(attributes & FILE_ATTRIBUTE_DIRECTORY))) {
destisdirectory = TRUE;
if (!(destname[strlenW(destname) - 1] == '\\')) strcatW(destname, slashW);
if (!ends_with_backslash( destname )) strcatW(destname, slashW);
WINE_TRACE("Directory, so full name is now '%s'\n", wine_dbgstr_w(destname));
}
}
......@@ -880,7 +880,7 @@ void WCMD_copy(WCHAR * args) {
/* If parameter is a directory, ensure it ends in \* */
attributes = GetFileAttributesW(srcpath);
if (srcpath[strlenW(srcpath) - 1] == '\\') {
if (ends_with_backslash( srcpath )) {
/* We need to know where the filename part starts, so append * and
recalculate the full resulting path */
......
......@@ -833,13 +833,8 @@ void WCMD_directory (WCHAR *args)
if ((strchrW(path, '*') == NULL) && (strchrW(path, '%') == NULL)) {
status = GetFileAttributesW(path);
if ((status != INVALID_FILE_ATTRIBUTES) && (status & FILE_ATTRIBUTE_DIRECTORY)) {
if (path[strlenW(path)-1] == '\\') {
strcatW (path, starW);
}
else {
static const WCHAR slashStarW[] = {'\\','*','\0'};
strcatW (path, slashStarW);
}
if (!ends_with_backslash( path )) strcatW( path, slashW );
strcatW (path, starW);
}
} else {
/* Special case wildcard search with no extension (ie parameters ending in '.') as
......
......@@ -148,6 +148,11 @@ static inline WCHAR *heap_strdupW(const WCHAR *str)
return ret;
}
static inline BOOL ends_with_backslash( const WCHAR *path )
{
return path[0] && path[strlenW(path) - 1] == '\\';
}
/* Data structure to hold context when executing batch files */
typedef struct _BATCH_CONTEXT {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment