Jon Griffiths : msvcrt: Make tests for [w]makepath pass.
Alexandre Julliard
julliard at winehq.org
Wed Jul 9 06:10:34 CDT 2008
Module: wine
Branch: master
Commit: 7b7cd31f058652d6f8ae760650be34b9f4d32ce7
URL: http://source.winehq.org/git/wine.git/?a=commit;h=7b7cd31f058652d6f8ae760650be34b9f4d32ce7
Author: Jon Griffiths <jon_p_griffiths at yahoo.com>
Date: Thu Jul 3 12:30:18 2008 -0700
msvcrt: Make tests for [w]makepath pass.
---
dlls/msvcrt/dir.c | 73 +++++++++++++++++++++++------------------------
dlls/msvcrt/tests/dir.c | 34 ++++++++--------------
2 files changed, 48 insertions(+), 59 deletions(-)
diff --git a/dlls/msvcrt/dir.c b/dlls/msvcrt/dir.c
index 7b1199c..0a28c59 100644
--- a/dlls/msvcrt/dir.c
+++ b/dlls/msvcrt/dir.c
@@ -865,28 +865,29 @@ VOID CDECL _makepath(char * path, const char * drive,
{
*p++ = drive[0];
*p++ = ':';
- *p = 0;
}
if (directory && directory[0])
{
- strcpy(p, directory);
- p += strlen(directory) - 1;
- if (*p != '/' && *p != '\\') {
- strcat(p, "\\");
- p++;
- }
- p++;
+ unsigned int len = strlen(directory);
+ memmove(p, directory, len);
+ p += len;
+ if (p[-1] != '/' && p[-1] != '\\')
+ *p++ = '\\';
}
if (filename && filename[0])
{
- strcpy(p, filename);
- if (extension && extension[0])
- {
- if ( extension[0] != '.' )
- strcat(p,".");
- strcat(p,extension);
- }
+ unsigned int len = strlen(filename);
+ memmove(p, filename, len);
+ p += len;
+ }
+ if (extension && extension[0])
+ {
+ if (extension[0] != '.')
+ *p++ = '.';
+ strcpy(p, extension);
}
+ else
+ *p = '\0';
TRACE("returning %s\n",path);
}
@@ -898,43 +899,41 @@ VOID CDECL _makepath(char * path, const char * drive,
VOID CDECL _wmakepath(MSVCRT_wchar_t *path, const MSVCRT_wchar_t *drive, const MSVCRT_wchar_t *directory,
const MSVCRT_wchar_t *filename, const MSVCRT_wchar_t *extension)
{
- MSVCRT_wchar_t ch;
+ MSVCRT_wchar_t *p = path;
+
TRACE("%s %s %s %s\n", debugstr_w(drive), debugstr_w(directory),
debugstr_w(filename), debugstr_w(extension));
if ( !path )
return;
- path[0] = 0;
if (drive && drive[0])
{
- path[0] = drive[0];
- path[1] = ':';
- path[2] = 0;
+ *p++ = drive[0];
+ *p++ = ':';
}
if (directory && directory[0])
{
- strcatW(path, directory);
- ch = path[strlenW(path) - 1];
- if (ch != '/' && ch != '\\')
- {
- static const MSVCRT_wchar_t backslashW[] = {'\\',0};
- strcatW(path, backslashW);
- }
+ unsigned int len = strlenW(directory);
+ memmove(p, directory, len * sizeof(MSVCRT_wchar_t));
+ p += len;
+ if (p[-1] != '/' && p[-1] != '\\')
+ *p++ = '\\';
}
if (filename && filename[0])
{
- strcatW(path, filename);
- if (extension && extension[0])
- {
- if ( extension[0] != '.' )
- {
- static const MSVCRT_wchar_t dotW[] = {'.',0};
- strcatW(path, dotW);
- }
- strcatW(path, extension);
- }
+ unsigned int len = strlenW(filename);
+ memmove(p, filename, len * sizeof(MSVCRT_wchar_t));
+ p += len;
+ }
+ if (extension && extension[0])
+ {
+ if (extension[0] != '.')
+ *p++ = '.';
+ strcpyW(p, extension);
}
+ else
+ *p = '\0';
TRACE("returning %s\n", debugstr_w(path));
}
diff --git a/dlls/msvcrt/tests/dir.c b/dlls/msvcrt/tests/dir.c
index 507add2..11a9820 100644
--- a/dlls/msvcrt/tests/dir.c
+++ b/dlls/msvcrt/tests/dir.c
@@ -39,14 +39,12 @@ typedef struct
const char* file;
const char* ext;
const char* expected;
- BOOL todoA;
- BOOL todoW;
} makepath_case;
#define USE_BUFF ((char*)~0ul)
static const makepath_case makepath_cases[] =
{
- { NULL, NULL, NULL, NULL, NULL, "", TRUE }, /* 0 */
+ { NULL, NULL, NULL, NULL, NULL, "" }, /* 0 */
{ NULL, "c", NULL, NULL, NULL, "c:" },
{ NULL, "c:", NULL, NULL, NULL, "c:" },
{ NULL, "c:\\", NULL, NULL, NULL, "c:" },
@@ -56,15 +54,15 @@ static const makepath_case makepath_cases[] =
{ NULL, NULL, NULL, "file", NULL, "file" },
{ NULL, NULL, NULL, "\\file", NULL, "\\file" },
{ NULL, NULL, NULL, "file", NULL, "file" },
- { NULL, NULL, NULL, NULL, "ext", ".ext", TRUE, TRUE }, /* 10 */
- { NULL, NULL, NULL, NULL, ".ext", ".ext", TRUE, TRUE },
- { "foo", NULL, NULL, NULL, NULL, "", TRUE },
- { "foo", USE_BUFF, NULL, NULL, NULL, "f:", FALSE, TRUE },
- { "foo", NULL, USE_BUFF, NULL, NULL, "foo\\", FALSE, TRUE },
- { "foo", NULL, NULL, USE_BUFF, NULL, "foo", FALSE, TRUE },
- { "foo", NULL, USE_BUFF, "file", NULL, "foo\\file", FALSE, TRUE },
- { "foo", NULL, USE_BUFF, "file", "ext", "foo\\file.ext", FALSE, TRUE },
- { "foo", NULL, NULL, USE_BUFF, "ext", "foo.ext", FALSE, TRUE },
+ { NULL, NULL, NULL, NULL, "ext", ".ext" }, /* 10 */
+ { NULL, NULL, NULL, NULL, ".ext", ".ext" },
+ { "foo", NULL, NULL, NULL, NULL, "" },
+ { "foo", USE_BUFF, NULL, NULL, NULL, "f:" },
+ { "foo", NULL, USE_BUFF, NULL, NULL, "foo\\" },
+ { "foo", NULL, NULL, USE_BUFF, NULL, "foo" },
+ { "foo", NULL, USE_BUFF, "file", NULL, "foo\\file" },
+ { "foo", NULL, USE_BUFF, "file", "ext", "foo\\file.ext" },
+ { "foo", NULL, NULL, USE_BUFF, "ext", "foo.ext" },
/* remaining combinations of USE_BUFF crash native */
{ NULL, "c", "dir", "file", "ext", "c:dir\\file.ext" },
{ NULL, "c:", "dir", "file", "ext", "c:dir\\file.ext" }, /* 20 */
@@ -98,11 +96,7 @@ static void test_makepath(void)
p->ext == USE_BUFF ? buffer : p->ext);
buffer[MAX_PATH - 1] = '\0';
- if (p->todoA) todo_wine {
- ok(!strcmp(p->expected, buffer), "got '%s' for case %d\n", buffer, i);
- }
- else
- ok(!strcmp(p->expected, buffer), "got '%s' for case %d\n", buffer, i);
+ ok(!strcmp(p->expected, buffer), "got '%s' for case %d\n", buffer, i);
/* Unicode */
if (p->drive != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->drive, -1, driveW, MAX_PATH);
@@ -123,11 +117,7 @@ static void test_makepath(void)
bufferW[MAX_PATH - 1] = '\0';
WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_PATH, NULL, NULL);
- if (p->todoW) todo_wine {
- ok(!strcmp(p->expected, buffer), "got '%s' for unicode case %d\n", buffer, i);
- }
- else
- ok(!strcmp(p->expected, buffer), "got '%s' for unicode case %d\n", buffer, i);
+ ok(!strcmp(p->expected, buffer), "got '%s' for unicode case %d\n", buffer, i);
}
}
More information about the wine-cvs
mailing list