diff --git a/reactos/dll/win32/msvcrt/msvcrt.spec b/reactos/dll/win32/msvcrt/msvcrt.spec index 2336c22d95f..db1d101a047 100644 --- a/reactos/dll/win32/msvcrt/msvcrt.spec +++ b/reactos/dll/win32/msvcrt/msvcrt.spec @@ -857,7 +857,7 @@ @ cdecl _spawnvp(long str ptr) @ cdecl _spawnvpe(long str 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_p_l # stub _sprintf_s_l @@ -1127,7 +1127,7 @@ @ cdecl _wspawnvp(long wstr ptr) @ cdecl _wspawnvpe(long wstr 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 _wstati64(wstr ptr) @ cdecl _wstat64(wstr ptr) diff --git a/reactos/lib/sdk/crt/crt.cmake b/reactos/lib/sdk/crt/crt.cmake index 66d8a057fe1..c01e1756c90 100644 --- a/reactos/lib/sdk/crt/crt.cmake +++ b/reactos/lib/sdk/crt/crt.cmake @@ -260,6 +260,10 @@ list(APPEND CRT_SOURCE stdlib/wmakpath_s.c string/_mbsnlen.c string/_mbstrnlen.c + string/_splitpath.c + string/_splitpath_s.c + string/_wsplitpath.c + string/_wsplitpath_s.c string/atof.c string/atoi.c string/atoi64.c @@ -271,7 +275,6 @@ list(APPEND CRT_SOURCE string/itow.c string/mbstowcs_s.c string/scanf.c - string/splitp.c string/strcoll.c string/strcspn.c string/strdup.c @@ -299,7 +302,6 @@ list(APPEND CRT_SOURCE string/wcstombs_s.c string/wcstoul.c string/wctype.c - string/wsplitp.c string/wtoi.c string/wtoi64.c string/wtol.c diff --git a/reactos/lib/sdk/crt/libcntpr.cmake b/reactos/lib/sdk/crt/libcntpr.cmake index 7c8e490b3ca..487c92e3a60 100644 --- a/reactos/lib/sdk/crt/libcntpr.cmake +++ b/reactos/lib/sdk/crt/libcntpr.cmake @@ -26,6 +26,8 @@ list(APPEND LIBCNTPR_SOURCE search/bsearch.c search/lfind.c stdlib/qsort.c + string/_splitpath.c + string/_wsplitpath.c string/ctype.c string/iswctype.c string/is_wctype.c @@ -46,7 +48,6 @@ list(APPEND LIBCNTPR_SOURCE string/itoa.c string/itow.c string/mbstowcs_nt.c - string/splitp.c string/strtol.c string/strtoul.c string/strtoull.c @@ -55,7 +56,6 @@ list(APPEND LIBCNTPR_SOURCE string/wcstombs_nt.c string/wcstoul.c string/wctype.c - string/wsplitp.c string/wtoi64.c string/wtoi.c string/wtol.c diff --git a/reactos/lib/sdk/crt/string/_splitpath.c b/reactos/lib/sdk/crt/string/_splitpath.c new file mode 100644 index 00000000000..0a14da494ad --- /dev/null +++ b/reactos/lib/sdk/crt/string/_splitpath.c @@ -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" diff --git a/reactos/lib/sdk/crt/string/_splitpath_s.c b/reactos/lib/sdk/crt/string/_splitpath_s.c new file mode 100644 index 00000000000..ed9c4e2a25b --- /dev/null +++ b/reactos/lib/sdk/crt/string/_splitpath_s.c @@ -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" diff --git a/reactos/lib/sdk/crt/string/_tsplitpath_x.h b/reactos/lib/sdk/crt/string/_tsplitpath_x.h new file mode 100644 index 00000000000..76473c98257 --- /dev/null +++ b/reactos/lib/sdk/crt/string/_tsplitpath_x.h @@ -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 +#include + +#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; +} + diff --git a/reactos/lib/sdk/crt/string/_wsplitpath.c b/reactos/lib/sdk/crt/string/_wsplitpath.c new file mode 100644 index 00000000000..7cca8189731 --- /dev/null +++ b/reactos/lib/sdk/crt/string/_wsplitpath.c @@ -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" diff --git a/reactos/lib/sdk/crt/string/_wsplitpath_s.c b/reactos/lib/sdk/crt/string/_wsplitpath_s.c new file mode 100644 index 00000000000..bebfc815d86 --- /dev/null +++ b/reactos/lib/sdk/crt/string/_wsplitpath_s.c @@ -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" diff --git a/reactos/lib/sdk/crt/string/splitp.c b/reactos/lib/sdk/crt/string/splitp.c deleted file mode 100644 index 7500c920f96..00000000000 --- a/reactos/lib/sdk/crt/string/splitp.c +++ /dev/null @@ -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 -#include - -/* - * @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'; - } -} - diff --git a/reactos/lib/sdk/crt/string/wsplitp.c b/reactos/lib/sdk/crt/string/wsplitp.c deleted file mode 100644 index 4655be577bd..00000000000 --- a/reactos/lib/sdk/crt/string/wsplitp.c +++ /dev/null @@ -1,7 +0,0 @@ - -#define _UNICODE -#define UNICODE - -#include - -#include "splitp.c"