Rewrote splitpath and wsplitpath to avoid modifying the path
separators.
This commit is contained in:
parent
2925d6ad17
commit
2937826866
|
@ -434,86 +434,44 @@ int _wrmdir(const MSVCRT_wchar_t * dir)
|
||||||
void _wsplitpath(const MSVCRT_wchar_t *inpath, MSVCRT_wchar_t *drv, MSVCRT_wchar_t *dir,
|
void _wsplitpath(const MSVCRT_wchar_t *inpath, MSVCRT_wchar_t *drv, MSVCRT_wchar_t *dir,
|
||||||
MSVCRT_wchar_t *fname, MSVCRT_wchar_t *ext )
|
MSVCRT_wchar_t *fname, MSVCRT_wchar_t *ext )
|
||||||
{
|
{
|
||||||
/* Modified PD code from 'snippets' collection. */
|
const MSVCRT_wchar_t *p, *end;
|
||||||
MSVCRT_wchar_t ch, *ptr, *p;
|
|
||||||
MSVCRT_wchar_t pathbuff[MAX_PATH],*path=pathbuff;
|
|
||||||
|
|
||||||
/* FIXME: Should be an strncpyW or something */
|
if (inpath[0] && inpath[1] == ':')
|
||||||
strcpyW(pathbuff, inpath);
|
|
||||||
TRACE(":splitting path %s\n",debugstr_w(path));
|
|
||||||
|
|
||||||
/* convert slashes to backslashes for searching */
|
|
||||||
for (ptr = (MSVCRT_wchar_t*)path; *ptr; ++ptr)
|
|
||||||
if (*ptr == '/')
|
|
||||||
*ptr = '\\';
|
|
||||||
|
|
||||||
/* look for drive spec */
|
|
||||||
if ((ptr = strchrW(path, ':')) != 0)
|
|
||||||
{
|
|
||||||
++ptr;
|
|
||||||
if (drv)
|
|
||||||
{
|
{
|
||||||
strncpyW(drv, path, ptr - path);
|
if (drv)
|
||||||
drv[ptr - path] = 0;
|
{
|
||||||
|
drv[0] = inpath[0];
|
||||||
|
drv[1] = inpath[1];
|
||||||
|
drv[2] = 0;
|
||||||
|
}
|
||||||
|
inpath += 2;
|
||||||
}
|
}
|
||||||
path = ptr;
|
else if (drv) drv[0] = 0;
|
||||||
}
|
|
||||||
else if (drv)
|
|
||||||
*drv = 0;
|
|
||||||
|
|
||||||
/* find rightmost backslash or leftmost colon */
|
/* look for end of directory part */
|
||||||
if ((ptr = strrchrW(path, '\\')) == NULL)
|
end = NULL;
|
||||||
ptr = (strchrW(path, ':'));
|
for (p = inpath; *p; p++) if (*p == '/' || *p == '\\') end = p + 1;
|
||||||
|
|
||||||
if (!ptr)
|
if (end) /* got a directory */
|
||||||
{
|
|
||||||
ptr = (MSVCRT_wchar_t *)path; /* no path */
|
|
||||||
if (dir)
|
|
||||||
*dir = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
++ptr; /* skip the delimiter */
|
|
||||||
if (dir)
|
|
||||||
{
|
{
|
||||||
ch = *ptr;
|
if (dir)
|
||||||
*ptr = 0;
|
{
|
||||||
strcpyW(dir, path);
|
memcpy( dir, inpath, (end - inpath) * sizeof(MSVCRT_wchar_t) );
|
||||||
*ptr = ch;
|
dir[end - inpath] = 0;
|
||||||
|
}
|
||||||
|
inpath = end;
|
||||||
}
|
}
|
||||||
}
|
else if (dir) dir[0] = 0;
|
||||||
|
|
||||||
|
/* look for extension */
|
||||||
|
for (end = inpath; *end; end++) if (*end == '.') break;
|
||||||
|
|
||||||
if ((p = strrchrW(ptr, '.')) == NULL)
|
|
||||||
{
|
|
||||||
if (fname)
|
if (fname)
|
||||||
strcpyW(fname, ptr);
|
|
||||||
if (ext)
|
|
||||||
*ext = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*p = 0;
|
|
||||||
if (fname)
|
|
||||||
strcpyW(fname, ptr);
|
|
||||||
*p = '.';
|
|
||||||
if (ext)
|
|
||||||
strcpyW(ext, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Fix pathological case - Win returns ':' as part of the
|
|
||||||
* directory when no drive letter is given.
|
|
||||||
*/
|
|
||||||
if (drv && drv[0] == ':')
|
|
||||||
{
|
|
||||||
*drv = 0;
|
|
||||||
if (dir)
|
|
||||||
{
|
{
|
||||||
pathbuff[0] = ':';
|
memcpy( fname, inpath, (end - inpath) * sizeof(MSVCRT_wchar_t) );
|
||||||
pathbuff[1] = 0;
|
fname[end - inpath] = 0;
|
||||||
strcatW(pathbuff,dir);
|
|
||||||
strcpyW(dir, pathbuff);
|
|
||||||
}
|
}
|
||||||
}
|
if (ext) strcpyW( ext, end );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* INTERNAL: Helper for _fullpath. Modified PD code from 'snippets'. */
|
/* INTERNAL: Helper for _fullpath. Modified PD code from 'snippets'. */
|
||||||
|
|
|
@ -347,82 +347,42 @@ LONGLONG __cdecl _atoi64( char *str )
|
||||||
void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
|
void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
|
||||||
char* fname, char * ext )
|
char* fname, char * ext )
|
||||||
{
|
{
|
||||||
/* Modified PD code from 'snippets' collection. */
|
const char *p, *end;
|
||||||
char ch, *ptr, *p;
|
|
||||||
char pathbuff[MAX_PATH], *path=pathbuff;
|
|
||||||
|
|
||||||
strcpy(pathbuff, inpath);
|
if (inpath[0] && inpath[1] == ':')
|
||||||
|
|
||||||
/* convert slashes to backslashes for searching */
|
|
||||||
for (ptr = (char*)path; *ptr; ++ptr)
|
|
||||||
if ('/' == *ptr)
|
|
||||||
*ptr = '\\';
|
|
||||||
|
|
||||||
/* look for drive spec */
|
|
||||||
if ('\0' != (ptr = strchr(path, ':')))
|
|
||||||
{
|
|
||||||
++ptr;
|
|
||||||
if (drv)
|
|
||||||
{
|
{
|
||||||
strncpy(drv, path, ptr - path);
|
if (drv)
|
||||||
drv[ptr - path] = '\0';
|
{
|
||||||
|
drv[0] = inpath[0];
|
||||||
|
drv[1] = inpath[1];
|
||||||
|
drv[2] = 0;
|
||||||
|
}
|
||||||
|
inpath += 2;
|
||||||
}
|
}
|
||||||
path = ptr;
|
else if (drv) drv[0] = 0;
|
||||||
}
|
|
||||||
else if (drv)
|
|
||||||
*drv = '\0';
|
|
||||||
|
|
||||||
/* find rightmost backslash or leftmost colon */
|
/* look for end of directory part */
|
||||||
if (NULL == (ptr = strrchr(path, '\\')))
|
end = NULL;
|
||||||
ptr = (strchr(path, ':'));
|
for (p = inpath; *p; p++) if (*p == '/' || *p == '\\') end = p + 1;
|
||||||
|
|
||||||
if (!ptr)
|
if (end) /* got a directory */
|
||||||
{
|
|
||||||
ptr = (char *)path; /* no path */
|
|
||||||
if (dir)
|
|
||||||
*dir = '\0';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
++ptr; /* skip the delimiter */
|
|
||||||
if (dir)
|
|
||||||
{
|
{
|
||||||
ch = *ptr;
|
if (dir)
|
||||||
*ptr = '\0';
|
{
|
||||||
strcpy(dir, path);
|
memcpy( dir, inpath, end - inpath );
|
||||||
*ptr = ch;
|
dir[end - inpath] = 0;
|
||||||
|
}
|
||||||
|
inpath = end;
|
||||||
}
|
}
|
||||||
}
|
else if (dir) dir[0] = 0;
|
||||||
|
|
||||||
|
/* look for extension */
|
||||||
|
for (end = inpath; *end; end++) if (*end == '.') break;
|
||||||
|
|
||||||
if (NULL == (p = strrchr(ptr, '.')))
|
|
||||||
{
|
|
||||||
if (fname)
|
if (fname)
|
||||||
strcpy(fname, ptr);
|
|
||||||
if (ext)
|
|
||||||
*ext = '\0';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*p = '\0';
|
|
||||||
if (fname)
|
|
||||||
strcpy(fname, ptr);
|
|
||||||
*p = '.';
|
|
||||||
if (ext)
|
|
||||||
strcpy(ext, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Fix pathological case - Win returns ':' as part of the
|
|
||||||
* directory when no drive letter is given.
|
|
||||||
*/
|
|
||||||
if (drv && drv[0] == ':')
|
|
||||||
{
|
|
||||||
*drv = '\0';
|
|
||||||
if (dir)
|
|
||||||
{
|
{
|
||||||
pathbuff[0] = ':';
|
memcpy( fname, inpath, end - inpath );
|
||||||
pathbuff[1] = '\0';
|
fname[end - inpath] = 0;
|
||||||
strcat(pathbuff,dir);
|
|
||||||
strcpy(dir,pathbuff);
|
|
||||||
}
|
}
|
||||||
}
|
if (ext) strcpy( ext, end );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue