- Update _makepath and _wmakepath to allow in place operation and separated extension processing, based on wine code

- Fixes all 14 msvcrt dir winetests

svn path=/trunk/; revision=38050
This commit is contained in:
Gregor Schneider 2008-12-13 21:06:47 +00:00
parent 1e4507a141
commit 681e0e0b24
2 changed files with 79 additions and 49 deletions

View file

@ -1,3 +1,16 @@
/*
* PROJECT: ReactOS CRT library
* LICENSE: See COPYING in the top level directory
* FILE: lib/sdk/crt/stdlib/makepath.c
* PURPOSE: Creates a path
* PROGRAMMERS: Wine team
* Copyright 1996,1998 Marcus Meissner
* Copyright 1996 Jukka Iivonen
* Copyright 1997,2000 Uwe Bonnes
* Copyright 2000 Jon Griffiths
*
*/
/* $Id$ /* $Id$
*/ */
#include <precomp.h> #include <precomp.h>
@ -9,29 +22,36 @@
*/ */
void _makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext) void _makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext)
{ {
int dir_len; char *p = path;
if ((drive != NULL) && (*drive)) { if ( !path )
path[0] = *drive; return;
path[1] = ':';
path[2] = 0;
} else {
(*path)=0;
}
if (dir != NULL) { if (drive && drive[0])
strcat(path, dir); {
dir_len = strlen(dir); *p++ = drive[0];
if (dir_len && *(dir + dir_len - 1) != '\\') *p++ = ':';
strcat(path, "\\");
} }
if (dir && dir[0])
if (fname != NULL) { {
strcat(path, fname); unsigned int len = strlen(dir);
if (ext != NULL && *ext != 0) { memmove(p, dir, len);
if (*ext != '.') p += len;
strcat(path, "."); if (p[-1] != '/' && p[-1] != '\\')
strcat(path, ext); *p++ = '\\';
}
} }
if (fname && fname[0])
{
unsigned int len = strlen(fname);
memmove(p, fname, len);
p += len;
}
if (ext && ext[0])
{
if (ext[0] != '.')
*p++ = '.';
strcpy(p, ext);
}
else
*p = '\0';
} }

View file

@ -1,11 +1,14 @@
/* /*
* COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS CRT library
* PROJECT: ReactOS system libraries * LICENSE: See COPYING in the top level directory
* FILE: lib/crt/?????? * FILE: lib/sdk/crt/stdlib/wmakpath.c
* PURPOSE: Unknown * PURPOSE: Creates a unicode path
* PROGRAMER: gdalsnes * PROGRAMMERS: Wine team
* UPDATE HISTORY: * Copyright 1996,1998 Marcus Meissner
* 25/11/05: Added license header * Copyright 1996 Jukka Iivonen
* Copyright 1997,2000 Uwe Bonnes
* Copyright 2000 Jon Griffiths
*
*/ */
/* $Id$ /* $Id$
@ -17,29 +20,36 @@
*/ */
void _wmakepath(wchar_t* path, const wchar_t* drive, const wchar_t* dir, const wchar_t* fname, const wchar_t* ext) void _wmakepath(wchar_t* path, const wchar_t* drive, const wchar_t* dir, const wchar_t* fname, const wchar_t* ext)
{ {
int dir_len; wchar_t *p = path;
if ((drive != NULL) && (*drive)) { if ( !path )
path[0] = *drive; return;
path[1] = L':';
path[2] = 0;
} else {
(*path) = 0;
}
if (dir != NULL) { if (drive && drive[0])
wcscat(path, dir); {
dir_len = wcslen(dir); *p++ = drive[0];
if (dir_len && *(dir + dir_len - 1) != L'\\') *p++ = ':';
wcscat(path, L"\\");
} }
if (dir && dir[0])
if (fname != NULL) { {
wcscat(path, fname); unsigned int len = strlenW(dir);
if (ext != NULL && *ext != 0) { memmove(p, dir, len * sizeof(wchar_t));
if (*ext != L'.') p += len;
wcscat(path, L"."); if (p[-1] != '/' && p[-1] != '\\')
wcscat(path, ext); *p++ = '\\';
}
} }
if (fname && fname[0])
{
unsigned int len = strlenW(fname);
memmove(p, fname, len * sizeof(wchar_t));
p += len;
}
if (ext && ext[0])
{
if (ext[0] != '.')
*p++ = '.';
strcpyW(p, ext);
}
else
*p = '\0';
} }