mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 13:14:41 +00:00
[CRT]
Rewrite _splitpath. See issue #6244 for more details. svn path=/trunk/; revision=52023
This commit is contained in:
parent
3e584471ab
commit
94ce2dcf66
1 changed files with 61 additions and 46 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
/*
|
||||||
|
* PROJECT: ReactOS Kernel
|
||||||
|
* LICENSE: BSD - See COPYING.ARM in the top level directory
|
||||||
|
* PURPOSE: CRT: implementation of _splitpath / _wsplitpath
|
||||||
|
* PROGRAMMERS: Timo Kreuzer
|
||||||
|
*/
|
||||||
|
|
||||||
#include <precomp.h>
|
#include <precomp.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
|
|
||||||
|
@ -6,64 +13,72 @@
|
||||||
*/
|
*/
|
||||||
void _tsplitpath(const _TCHAR* path, _TCHAR* drive, _TCHAR* dir, _TCHAR* fname, _TCHAR* ext)
|
void _tsplitpath(const _TCHAR* path, _TCHAR* drive, _TCHAR* dir, _TCHAR* fname, _TCHAR* ext)
|
||||||
{
|
{
|
||||||
_TCHAR* tmp_drive = NULL;
|
const _TCHAR *src, *dir_start, *file_start = 0, *ext_start = 0;
|
||||||
_TCHAR* tmp_dir = NULL;
|
|
||||||
_TCHAR* tmp_ext = NULL;
|
|
||||||
|
|
||||||
tmp_drive = (_TCHAR*)_tcschr(path,':');
|
/* Truncate all output strings */
|
||||||
if (drive)
|
if (drive) drive[0] = '\0';
|
||||||
|
if (dir) dir[0] = '\0';
|
||||||
|
if (fname) fname[0] = '\0';
|
||||||
|
if (ext) ext[0] = '\0';
|
||||||
|
|
||||||
|
/* Check parameter */
|
||||||
|
if (!path)
|
||||||
{
|
{
|
||||||
if (tmp_drive)
|
__set_errno(EINVAL);
|
||||||
{
|
return;
|
||||||
_tcsncpy(drive,tmp_drive-1,2);
|
|
||||||
*(drive+2) = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*drive = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!tmp_drive)
|
|
||||||
{
|
|
||||||
tmp_drive = (_TCHAR*)path - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_dir = (_TCHAR*)_tcsrchr(path,'\\');
|
/* Skip '\\?\' prefix */
|
||||||
if (dir)
|
if ((path[0] == '\\') && (path[1] == '\\') &&
|
||||||
|
(path[2] == '?') && (path[3] == '\\')) path += 4;
|
||||||
|
|
||||||
|
if (path[0] == '\0') return;
|
||||||
|
|
||||||
|
/* Check if we have a drive letter (only 1 char supported) */
|
||||||
|
if (path[1] == ':')
|
||||||
{
|
{
|
||||||
if (tmp_dir)
|
if (drive)
|
||||||
{
|
{
|
||||||
_tcsncpy(dir,tmp_drive+1,tmp_dir-tmp_drive);
|
drive[0] = path[0];
|
||||||
*(dir+(tmp_dir-tmp_drive)) = 0;
|
drive[1] = ':';
|
||||||
}
|
drive[2] = '\0';
|
||||||
else
|
|
||||||
{
|
|
||||||
*dir =0;
|
|
||||||
}
|
}
|
||||||
|
path += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Scan the rest of the string */
|
||||||
|
dir_start = path;
|
||||||
|
while (*path != '\0')
|
||||||
|
{
|
||||||
|
/* Remember last path seperator and last dot */
|
||||||
|
if ((*path == '\\') || (*path == '/')) file_start = path + 1;
|
||||||
|
if (*path == '.') ext_start = path;
|
||||||
|
path++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the dot is before the last dir separator, it's part
|
/* Check if we got */
|
||||||
* of a directory name, not the start of the extension */
|
if (!file_start) file_start = path;
|
||||||
if (!tmp_ext || tmp_ext < tmp_dir)
|
if (!ext_start || ext_start < file_start) ext_start = path;
|
||||||
|
|
||||||
|
if (dir)
|
||||||
{
|
{
|
||||||
tmp_ext = (_TCHAR*)path+_tcslen(path);
|
src = dir_start;
|
||||||
}
|
while (src < file_start) *dir++ = *src++;
|
||||||
if (ext)
|
*dir = '\0';
|
||||||
{
|
|
||||||
_tcscpy(ext,tmp_ext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fname)
|
if (fname)
|
||||||
{
|
{
|
||||||
if (tmp_dir)
|
src = file_start;
|
||||||
{
|
while (src < ext_start) *fname++ = *src++;
|
||||||
_tcsncpy(fname,tmp_dir+1,tmp_ext-tmp_dir-1);
|
*fname = '\0';
|
||||||
*(fname+(tmp_ext-tmp_dir-1)) = 0;
|
}
|
||||||
}
|
|
||||||
else
|
if (ext)
|
||||||
{
|
{
|
||||||
_tcsncpy(fname,tmp_drive+1,tmp_ext-tmp_drive-1);
|
src = ext_start;
|
||||||
*(fname+(tmp_ext-path))=0;
|
while (*src != '\0') *ext++ = *src++;
|
||||||
}
|
*ext = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue