Alexandre Julliard : cmd: Add a helper function to check if a path ends with a backslash.
Alexandre Julliard
julliard at wine.codeweavers.com
Thu Oct 30 09:23:15 CDT 2014
Module: wine
Branch: master
Commit: 3d3c5ab4006de7a80af421ddfeb2cad699fb03f0
URL: http://source.winehq.org/git/wine.git/?a=commit;h=3d3c5ab4006de7a80af421ddfeb2cad699fb03f0
Author: Alexandre Julliard <julliard at winehq.org>
Date: Thu Oct 30 13:11:27 2014 +0900
cmd: Add a helper function to check if a path ends with a backslash.
---
programs/cmd/builtins.c | 6 +++---
programs/cmd/directory.c | 9 ++-------
programs/cmd/wcmd.h | 5 +++++
3 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index f7db4a9..6751d3e 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -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 */
diff --git a/programs/cmd/directory.c b/programs/cmd/directory.c
index 678e2a1..91142be 100644
--- a/programs/cmd/directory.c
+++ b/programs/cmd/directory.c
@@ -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
diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h
index e5a0138..c135621 100644
--- a/programs/cmd/wcmd.h
+++ b/programs/cmd/wcmd.h
@@ -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 {
More information about the wine-cvs
mailing list