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

This commit is contained in:
Alexandre Julliard 2014-10-30 13:11:27 +09:00
parent 9c5f23121a
commit 3d3c5ab400
3 changed files with 10 additions and 10 deletions

View File

@ -798,12 +798,12 @@ void WCMD_copy(WCHAR * args) {
/* If parameter is a directory, ensure it ends in \ */ /* If parameter is a directory, ensure it ends in \ */
attributes = GetFileAttributesW(destname); attributes = GetFileAttributesW(destname);
if ((destname[strlenW(destname) - 1] == '\\') || if (ends_with_backslash( destname ) ||
((attributes != INVALID_FILE_ATTRIBUTES) && ((attributes != INVALID_FILE_ATTRIBUTES) &&
(attributes & FILE_ATTRIBUTE_DIRECTORY))) { (attributes & FILE_ATTRIBUTE_DIRECTORY))) {
destisdirectory = TRUE; 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)); 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 \* */ /* If parameter is a directory, ensure it ends in \* */
attributes = GetFileAttributesW(srcpath); 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 /* We need to know where the filename part starts, so append * and
recalculate the full resulting path */ recalculate the full resulting path */

View File

@ -833,14 +833,9 @@ void WCMD_directory (WCHAR *args)
if ((strchrW(path, '*') == NULL) && (strchrW(path, '%') == NULL)) { if ((strchrW(path, '*') == NULL) && (strchrW(path, '%') == NULL)) {
status = GetFileAttributesW(path); status = GetFileAttributesW(path);
if ((status != INVALID_FILE_ATTRIBUTES) && (status & FILE_ATTRIBUTE_DIRECTORY)) { if ((status != INVALID_FILE_ATTRIBUTES) && (status & FILE_ATTRIBUTE_DIRECTORY)) {
if (path[strlenW(path)-1] == '\\') { if (!ends_with_backslash( path )) strcatW( path, slashW );
strcatW (path, starW); strcatW (path, starW);
} }
else {
static const WCHAR slashStarW[] = {'\\','*','\0'};
strcatW (path, slashStarW);
}
}
} else { } else {
/* Special case wildcard search with no extension (ie parameters ending in '.') as /* Special case wildcard search with no extension (ie parameters ending in '.') as
GetFullPathName strips off the additional '.' */ GetFullPathName strips off the additional '.' */

View File

@ -148,6 +148,11 @@ static inline WCHAR *heap_strdupW(const WCHAR *str)
return ret; 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 */ /* Data structure to hold context when executing batch files */
typedef struct _BATCH_CONTEXT { typedef struct _BATCH_CONTEXT {