Commit 0db689ed authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Add _wsplitpath_s.

Implementation copied from msvcrt. Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 911810c5
......@@ -1554,6 +1554,7 @@
@ cdecl -ret64 _wcstoui64(wstr ptr long)
@ cdecl _wcsupr(wstr)
@ cdecl _wcsupr_s(wstr long)
@ cdecl _wsplitpath_s(wstr ptr long ptr long ptr long ptr long)
@ cdecl _wtoi(wstr)
@ cdecl -ret64 _wtoi64(wstr)
@ cdecl _wtol(wstr)
......
......@@ -1299,3 +1299,79 @@ LONGLONG __cdecl _wtoi64( LPCWSTR str )
return bMinus ? -RunningTotal : RunningTotal;
}
/******************************************************************
* _wsplitpath_s (NTDLL.@)
*/
errno_t __cdecl _wsplitpath_s( const wchar_t *inpath, wchar_t *drive, size_t sz_drive,
wchar_t *dir, size_t sz_dir, wchar_t *fname, size_t sz_fname,
wchar_t *ext, size_t sz_ext )
{
const wchar_t *p, *end;
if (!inpath || (!drive && sz_drive) ||
(drive && !sz_drive) ||
(!dir && sz_dir) ||
(dir && !sz_dir) ||
(!fname && sz_fname) ||
(fname && !sz_fname) ||
(!ext && sz_ext) ||
(ext && !sz_ext))
return EINVAL;
if (inpath[0] && inpath[1] == ':')
{
if (drive)
{
if (sz_drive <= 2) goto error;
drive[0] = inpath[0];
drive[1] = inpath[1];
drive[2] = 0;
}
inpath += 2;
}
else if (drive) drive[0] = '\0';
/* look for end of directory part */
end = NULL;
for (p = inpath; *p; p++) if (*p == '/' || *p == '\\') end = p + 1;
if (end) /* got a directory */
{
if (dir)
{
if (sz_dir <= end - inpath) goto error;
memcpy( dir, inpath, (end - inpath) * sizeof(wchar_t) );
dir[end - inpath] = 0;
}
inpath = end;
}
else if (dir) dir[0] = 0;
/* look for extension: what's after the last dot */
end = NULL;
for (p = inpath; *p; p++) if (*p == '.') end = p;
if (!end) end = p; /* there's no extension */
if (fname)
{
if (sz_fname <= end - inpath) goto error;
memcpy( fname, inpath, (end - inpath) * sizeof(wchar_t) );
fname[end - inpath] = 0;
}
if (ext)
{
if (sz_ext <= wcslen(end)) goto error;
wcscpy( ext, end );
}
return 0;
error:
if (drive) drive[0] = 0;
if (dir) dir[0] = 0;
if (fname) fname[0]= 0;
if (ext) ext[0]= 0;
return ERANGE;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment