mirror of
https://github.com/reactos/reactos.git
synced 2025-06-01 07:28:19 +00:00
[CRT]
Implement _splitpath_s and _wsplitpath_s [MSVCRT] Export _splitpath_s and _wsplitpath_s svn path=/trunk/; revision=58517
This commit is contained in:
parent
abf1110ae8
commit
05a927e9e3
10 changed files with 202 additions and 107 deletions
|
@ -857,7 +857,7 @@
|
||||||
@ cdecl _spawnvp(long str ptr)
|
@ cdecl _spawnvp(long str ptr)
|
||||||
@ cdecl _spawnvpe(long str ptr ptr)
|
@ cdecl _spawnvpe(long str ptr ptr)
|
||||||
@ cdecl _splitpath(str ptr ptr ptr ptr)
|
@ cdecl _splitpath(str ptr ptr ptr ptr)
|
||||||
# stub _splitpath_s
|
@ cdecl _splitpath_s(str ptr long ptr long ptr long ptr long)
|
||||||
# stub _sprintf_l
|
# stub _sprintf_l
|
||||||
# stub _sprintf_p_l
|
# stub _sprintf_p_l
|
||||||
# stub _sprintf_s_l
|
# stub _sprintf_s_l
|
||||||
|
@ -1127,7 +1127,7 @@
|
||||||
@ cdecl _wspawnvp(long wstr ptr)
|
@ cdecl _wspawnvp(long wstr ptr)
|
||||||
@ cdecl _wspawnvpe(long wstr ptr ptr)
|
@ cdecl _wspawnvpe(long wstr ptr ptr)
|
||||||
@ cdecl _wsplitpath(wstr ptr ptr ptr ptr)
|
@ cdecl _wsplitpath(wstr ptr ptr ptr ptr)
|
||||||
# @ cdecl _wsplitpath_s(wstr ptr long ptr long ptr long ptr long)
|
@ cdecl _wsplitpath_s(wstr ptr long ptr long ptr long ptr long)
|
||||||
@ cdecl _wstat(wstr ptr)
|
@ cdecl _wstat(wstr ptr)
|
||||||
@ cdecl _wstati64(wstr ptr)
|
@ cdecl _wstati64(wstr ptr)
|
||||||
@ cdecl _wstat64(wstr ptr)
|
@ cdecl _wstat64(wstr ptr)
|
||||||
|
|
|
@ -260,6 +260,10 @@ list(APPEND CRT_SOURCE
|
||||||
stdlib/wmakpath_s.c
|
stdlib/wmakpath_s.c
|
||||||
string/_mbsnlen.c
|
string/_mbsnlen.c
|
||||||
string/_mbstrnlen.c
|
string/_mbstrnlen.c
|
||||||
|
string/_splitpath.c
|
||||||
|
string/_splitpath_s.c
|
||||||
|
string/_wsplitpath.c
|
||||||
|
string/_wsplitpath_s.c
|
||||||
string/atof.c
|
string/atof.c
|
||||||
string/atoi.c
|
string/atoi.c
|
||||||
string/atoi64.c
|
string/atoi64.c
|
||||||
|
@ -271,7 +275,6 @@ list(APPEND CRT_SOURCE
|
||||||
string/itow.c
|
string/itow.c
|
||||||
string/mbstowcs_s.c
|
string/mbstowcs_s.c
|
||||||
string/scanf.c
|
string/scanf.c
|
||||||
string/splitp.c
|
|
||||||
string/strcoll.c
|
string/strcoll.c
|
||||||
string/strcspn.c
|
string/strcspn.c
|
||||||
string/strdup.c
|
string/strdup.c
|
||||||
|
@ -299,7 +302,6 @@ list(APPEND CRT_SOURCE
|
||||||
string/wcstombs_s.c
|
string/wcstombs_s.c
|
||||||
string/wcstoul.c
|
string/wcstoul.c
|
||||||
string/wctype.c
|
string/wctype.c
|
||||||
string/wsplitp.c
|
|
||||||
string/wtoi.c
|
string/wtoi.c
|
||||||
string/wtoi64.c
|
string/wtoi64.c
|
||||||
string/wtol.c
|
string/wtol.c
|
||||||
|
|
|
@ -26,6 +26,8 @@ list(APPEND LIBCNTPR_SOURCE
|
||||||
search/bsearch.c
|
search/bsearch.c
|
||||||
search/lfind.c
|
search/lfind.c
|
||||||
stdlib/qsort.c
|
stdlib/qsort.c
|
||||||
|
string/_splitpath.c
|
||||||
|
string/_wsplitpath.c
|
||||||
string/ctype.c
|
string/ctype.c
|
||||||
string/iswctype.c
|
string/iswctype.c
|
||||||
string/is_wctype.c
|
string/is_wctype.c
|
||||||
|
@ -46,7 +48,6 @@ list(APPEND LIBCNTPR_SOURCE
|
||||||
string/itoa.c
|
string/itoa.c
|
||||||
string/itow.c
|
string/itow.c
|
||||||
string/mbstowcs_nt.c
|
string/mbstowcs_nt.c
|
||||||
string/splitp.c
|
|
||||||
string/strtol.c
|
string/strtol.c
|
||||||
string/strtoul.c
|
string/strtoul.c
|
||||||
string/strtoull.c
|
string/strtoull.c
|
||||||
|
@ -55,7 +56,6 @@ list(APPEND LIBCNTPR_SOURCE
|
||||||
string/wcstombs_nt.c
|
string/wcstombs_nt.c
|
||||||
string/wcstoul.c
|
string/wcstoul.c
|
||||||
string/wctype.c
|
string/wctype.c
|
||||||
string/wsplitp.c
|
|
||||||
string/wtoi64.c
|
string/wtoi64.c
|
||||||
string/wtoi.c
|
string/wtoi.c
|
||||||
string/wtol.c
|
string/wtol.c
|
||||||
|
|
11
reactos/lib/sdk/crt/string/_splitpath.c
Normal file
11
reactos/lib/sdk/crt/string/_splitpath.c
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/*
|
||||||
|
* COPYRIGHT: GNU GPL, see COPYING in the top level directory
|
||||||
|
* PROJECT: ReactOS crt library
|
||||||
|
* FILE: lib/sdk/crt/string/_splitpath.c
|
||||||
|
* PURPOSE: Implementation of _splitpath
|
||||||
|
* PROGRAMMER: Timo Kreuzer
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _tsplitpath_x _splitpath
|
||||||
|
|
||||||
|
#include "_tsplitpath_x.h"
|
12
reactos/lib/sdk/crt/string/_splitpath_s.c
Normal file
12
reactos/lib/sdk/crt/string/_splitpath_s.c
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
/*
|
||||||
|
* COPYRIGHT: GNU GPL, see COPYING in the top level directory
|
||||||
|
* PROJECT: ReactOS crt library
|
||||||
|
* FILE: lib/sdk/crt/string/_splitpath_s.c
|
||||||
|
* PURPOSE: Implementation of _splitpath_s
|
||||||
|
* PROGRAMMER: Timo Kreuzer
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _tsplitpath_x _splitpath_s
|
||||||
|
#define IS_SECAPI 1
|
||||||
|
|
||||||
|
#include "_tsplitpath_x.h"
|
146
reactos/lib/sdk/crt/string/_tsplitpath_x.h
Normal file
146
reactos/lib/sdk/crt/string/_tsplitpath_x.h
Normal file
|
@ -0,0 +1,146 @@
|
||||||
|
/*
|
||||||
|
* PROJECT: ReactOS Kernel
|
||||||
|
* LICENSE: BSD - See COPYING.ARM in the top level directory
|
||||||
|
* PURPOSE: CRT: implementation of __[w]splitpath[_s]
|
||||||
|
* PROGRAMMERS: Timo Kreuzer
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <precomp.h>
|
||||||
|
#include <tchar.h>
|
||||||
|
|
||||||
|
#if IS_SECAPI
|
||||||
|
#define _FAILURE -1
|
||||||
|
#define _SUCCESS 0
|
||||||
|
|
||||||
|
_Check_return_wat_
|
||||||
|
_CRTIMP_ALTERNATIVE
|
||||||
|
errno_t
|
||||||
|
__cdecl
|
||||||
|
_tsplitpath_x(
|
||||||
|
_In_z_ const _TCHAR* path,
|
||||||
|
_Out_writes_opt_z_(drive_size) _TCHAR* drive,
|
||||||
|
_In_ size_t drive_size,
|
||||||
|
_Out_writes_opt_z_(dir_size) _TCHAR* dir,
|
||||||
|
_In_ size_t dir_size,
|
||||||
|
_Out_writes_opt_z_(fname_size) _TCHAR* fname,
|
||||||
|
_In_ size_t fname_size,
|
||||||
|
_Out_writes_opt_z_(ext_size) _TCHAR* ext,
|
||||||
|
_In_ size_t ext_size)
|
||||||
|
#else
|
||||||
|
#define _FAILURE
|
||||||
|
#define _SUCCESS
|
||||||
|
|
||||||
|
_CRT_INSECURE_DEPRECATE(_splitpath_s)
|
||||||
|
_CRTIMP
|
||||||
|
void
|
||||||
|
__cdecl
|
||||||
|
_tsplitpath_x(
|
||||||
|
_In_z_ const _TCHAR* path,
|
||||||
|
_Pre_maybenull_ _Post_z_ _TCHAR* drive,
|
||||||
|
_Pre_maybenull_ _Post_z_ _TCHAR* dir,
|
||||||
|
_Pre_maybenull_ _Post_z_ _TCHAR* fname,
|
||||||
|
_Pre_maybenull_ _Post_z_ _TCHAR* ext)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
const _TCHAR *src, *dir_start, *file_start = 0, *ext_start = 0;
|
||||||
|
size_t count;
|
||||||
|
#if !IS_SECAPI
|
||||||
|
const size_t drive_size = INT_MAX, dir_size = INT_MAX,
|
||||||
|
fname_size = INT_MAX, ext_size = INT_MAX;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if IS_SECAPI
|
||||||
|
/* Validate parameters */
|
||||||
|
if (MSVCRT_CHECK_PMT((path == NULL) ||
|
||||||
|
((drive != NULL) && (drive_size == 0)) ||
|
||||||
|
((dir != NULL) && (dir_size == 0)) ||
|
||||||
|
((fname != NULL) && (fname_size == 0)) ||
|
||||||
|
((ext != NULL) && (ext_size == 0))))
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Truncate all output strings */
|
||||||
|
if (drive) drive[0] = '\0';
|
||||||
|
if (dir) dir[0] = '\0';
|
||||||
|
if (fname) fname[0] = '\0';
|
||||||
|
if (ext) ext[0] = '\0';
|
||||||
|
|
||||||
|
#if WINVER >= 0x600
|
||||||
|
/* Check parameter */
|
||||||
|
if (!path)
|
||||||
|
{
|
||||||
|
#ifndef _LIBCNT_
|
||||||
|
_set_errno(EINVAL);
|
||||||
|
#endif
|
||||||
|
return _FAILURE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
_Analysis_assume_(path != 0);
|
||||||
|
|
||||||
|
#if WINVER == 0x600
|
||||||
|
/* Skip '\\?\' prefix */
|
||||||
|
if ((path[0] == '\\') && (path[1] == '\\') &&
|
||||||
|
(path[2] == '?') && (path[3] == '\\')) path += 4;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (path[0] == '\0') return _FAILURE;
|
||||||
|
|
||||||
|
/* Check if we have a drive letter (only 1 char supported) */
|
||||||
|
if (path[1] == ':')
|
||||||
|
{
|
||||||
|
if (drive && (drive_size >= 3))
|
||||||
|
{
|
||||||
|
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 separator and last dot */
|
||||||
|
if ((*path == '\\') || (*path == '/')) file_start = path + 1;
|
||||||
|
if (*path == '.') ext_start = path;
|
||||||
|
path++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if we got a file name / extension */
|
||||||
|
if (!file_start)
|
||||||
|
file_start = dir_start;
|
||||||
|
if (!ext_start || ext_start < file_start)
|
||||||
|
ext_start = path;
|
||||||
|
|
||||||
|
if (dir)
|
||||||
|
{
|
||||||
|
src = dir_start;
|
||||||
|
count = dir_size - 1;
|
||||||
|
while (src < file_start && count--) *dir++ = *src++;
|
||||||
|
*dir = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fname)
|
||||||
|
{
|
||||||
|
src = file_start;
|
||||||
|
count = fname_size - 1;
|
||||||
|
while (src < ext_start && count--) *fname++ = *src++;
|
||||||
|
*fname = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ext)
|
||||||
|
{
|
||||||
|
src = ext_start;
|
||||||
|
count = ext_size - 1;
|
||||||
|
while (*src != '\0' && count--) *ext++ = *src++;
|
||||||
|
*ext = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return _SUCCESS;
|
||||||
|
}
|
||||||
|
|
12
reactos/lib/sdk/crt/string/_wsplitpath.c
Normal file
12
reactos/lib/sdk/crt/string/_wsplitpath.c
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
/*
|
||||||
|
* COPYRIGHT: GNU GPL, see COPYING in the top level directory
|
||||||
|
* PROJECT: ReactOS crt library
|
||||||
|
* FILE: lib/sdk/crt/string/_wsplitpath.c
|
||||||
|
* PURPOSE: Implementation of _wsplitpath
|
||||||
|
* PROGRAMMER: Timo Kreuzer
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _tsplitpath_x _wsplitpath
|
||||||
|
#define _UNICODE
|
||||||
|
|
||||||
|
#include "_tsplitpath_x.h"
|
13
reactos/lib/sdk/crt/string/_wsplitpath_s.c
Normal file
13
reactos/lib/sdk/crt/string/_wsplitpath_s.c
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* COPYRIGHT: GNU GPL, see COPYING in the top level directory
|
||||||
|
* PROJECT: ReactOS crt library
|
||||||
|
* FILE: lib/sdk/crt/string/_wsplitpath_s.c
|
||||||
|
* PURPOSE: Implementation of _wsplitpath_s
|
||||||
|
* PROGRAMMER: Timo Kreuzer
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _tsplitpath_x _wsplitpath_s
|
||||||
|
#define _UNICODE
|
||||||
|
#define IS_SECAPI 1
|
||||||
|
|
||||||
|
#include "_tsplitpath_x.h"
|
|
@ -1,94 +0,0 @@
|
||||||
/*
|
|
||||||
* 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';
|
|
||||||
|
|
||||||
#if WINVER >= 0x600
|
|
||||||
/* Check parameter */
|
|
||||||
if (!path)
|
|
||||||
{
|
|
||||||
#ifndef _LIBCNT_
|
|
||||||
_set_errno(EINVAL);
|
|
||||||
#endif
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_Analysis_assume_(path != 0);
|
|
||||||
|
|
||||||
#if WINVER == 0x600
|
|
||||||
/* Skip '\\?\' prefix */
|
|
||||||
if ((path[0] == '\\') && (path[1] == '\\') &&
|
|
||||||
(path[2] == '?') && (path[3] == '\\')) path += 4;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
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 a file name / extension */
|
|
||||||
if (!file_start)
|
|
||||||
file_start = dir_start;
|
|
||||||
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';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
|
|
||||||
#define _UNICODE
|
|
||||||
#define UNICODE
|
|
||||||
|
|
||||||
#include <tchar.h>
|
|
||||||
|
|
||||||
#include "splitp.c"
|
|
Loading…
Reference in a new issue