2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * PURPOSE: CRT: implementation of __[w]splitpath[_s]
5 * PROGRAMMERS: Timo Kreuzer
20 _In_z_
const _TCHAR
* path
,
21 _Out_writes_opt_z_(drive_size
) _TCHAR
* drive
,
22 _In_
size_t drive_size
,
23 _Out_writes_opt_z_(dir_size
) _TCHAR
* dir
,
25 _Out_writes_opt_z_(fname_size
) _TCHAR
* fname
,
26 _In_
size_t fname_size
,
27 _Out_writes_opt_z_(ext_size
) _TCHAR
* ext
,
33 _CRT_INSECURE_DEPRECATE(_splitpath_s
)
38 _In_z_
const _TCHAR
* path
,
39 _Pre_maybenull_ _Post_z_ _TCHAR
* drive
,
40 _Pre_maybenull_ _Post_z_ _TCHAR
* dir
,
41 _Pre_maybenull_ _Post_z_ _TCHAR
* fname
,
42 _Pre_maybenull_ _Post_z_ _TCHAR
* ext
)
45 const _TCHAR
*src
, *dir_start
, *file_start
= 0, *ext_start
= 0;
48 const size_t drive_size
= INT_MAX
, dir_size
= INT_MAX
,
49 fname_size
= INT_MAX
, ext_size
= INT_MAX
;
53 /* Validate parameters */
54 if (MSVCRT_CHECK_PMT((path
== NULL
) ||
55 ((drive
!= NULL
) && (drive_size
== 0)) ||
56 ((dir
!= NULL
) && (dir_size
== 0)) ||
57 ((fname
!= NULL
) && (fname_size
== 0)) ||
58 ((ext
!= NULL
) && (ext_size
== 0))))
65 /* Truncate all output strings */
66 if (drive
) drive
[0] = '\0';
67 if (dir
) dir
[0] = '\0';
68 if (fname
) fname
[0] = '\0';
69 if (ext
) ext
[0] = '\0';
82 _Analysis_assume_(path
!= 0);
85 /* Skip '\\?\' prefix */
86 if ((path
[0] == '\\') && (path
[1] == '\\') &&
87 (path
[2] == '?') && (path
[3] == '\\')) path
+= 4;
90 if (path
[0] == '\0') return _FAILURE
;
92 /* Check if we have a drive letter (only 1 char supported) */
95 if (drive
&& (drive_size
>= 3))
104 /* Scan the rest of the string */
106 while (*path
!= '\0')
108 /* Remember last path separator and last dot */
109 if ((*path
== '\\') || (*path
== '/')) file_start
= path
+ 1;
110 if (*path
== '.') ext_start
= path
;
114 /* Check if we got a file name / extension */
116 file_start
= dir_start
;
117 if (!ext_start
|| ext_start
< file_start
)
123 count
= dir_size
- 1;
124 while (src
< file_start
&& count
--) *dir
++ = *src
++;
131 count
= fname_size
- 1;
132 while (src
< ext_start
&& count
--) *fname
++ = *src
++;
139 count
= ext_size
- 1;
140 while (*src
!= '\0' && count
--) *ext
++ = *src
++;