mirror of
https://github.com/reactos/reactos.git
synced 2025-04-21 12:40:33 +00:00
84 lines
1.9 KiB
C
84 lines
1.9 KiB
C
/*
|
|
* 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 <tchar.h>
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
void _tsplitpath(const _TCHAR* path, _TCHAR* drive, _TCHAR* dir, _TCHAR* fname, _TCHAR* ext)
|
|
{
|
|
const _TCHAR *src, *dir_start, *file_start = 0, *ext_start = 0;
|
|
|
|
/* Truncate all output strings */
|
|
if (drive) drive[0] = '\0';
|
|
if (dir) dir[0] = '\0';
|
|
if (fname) fname[0] = '\0';
|
|
if (ext) ext[0] = '\0';
|
|
|
|
/* Check parameter */
|
|
if (!path)
|
|
{
|
|
__set_errno(EINVAL);
|
|
return;
|
|
}
|
|
|
|
/* Skip '\\?\' prefix */
|
|
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 (drive)
|
|
{
|
|
drive[0] = path[0];
|
|
drive[1] = ':';
|
|
drive[2] = '\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++;
|
|
}
|
|
|
|
/* Check if we got */
|
|
if (!file_start) file_start = path;
|
|
if (!ext_start || ext_start < file_start) ext_start = path;
|
|
|
|
if (dir)
|
|
{
|
|
src = dir_start;
|
|
while (src < file_start) *dir++ = *src++;
|
|
*dir = '\0';
|
|
}
|
|
|
|
if (fname)
|
|
{
|
|
src = file_start;
|
|
while (src < ext_start) *fname++ = *src++;
|
|
*fname = '\0';
|
|
}
|
|
|
|
if (ext)
|
|
{
|
|
src = ext_start;
|
|
while (*src != '\0') *ext++ = *src++;
|
|
*ext = '\0';
|
|
}
|
|
}
|
|
|