Commit 5d2f0688 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Add _splitpath_s.

Implementation copied from msvcrt. Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 0db689ed
......@@ -1524,6 +1524,7 @@
@ varargs _snwprintf_s(ptr long long wstr)
@ varargs _swprintf(ptr wstr) NTDLL_swprintf
@ cdecl _splitpath(str ptr ptr ptr ptr)
@ cdecl _splitpath_s(str ptr long ptr long ptr long ptr long)
@ cdecl _strcmpi(str str) _stricmp
@ cdecl _stricmp(str str)
@ cdecl _strlwr(str)
......
......@@ -1852,37 +1852,37 @@ int WINAPIV sscanf( const char *str, const char *format, ... )
}
/*********************************************************************
* _splitpath (NTDLL.@)
*
* Split a path into its component pieces.
*
* PARAMS
* inpath [I] Path to split
* drv [O] Destination for drive component (e.g. "A:"). Must be at least 3 characters.
* dir [O] Destination for directory component. Should be at least MAX_PATH characters.
* fname [O] Destination for File name component. Should be at least MAX_PATH characters.
* ext [O] Destination for file extension component. Should be at least MAX_PATH characters.
*
* RETURNS
* Nothing.
/******************************************************************
* _splitpath_s (NTDLL.@)
*/
void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
char* fname, char * ext )
errno_t __cdecl _splitpath_s( const char *inpath, char *drive, size_t sz_drive,
char *dir, size_t sz_dir, char *fname, size_t sz_fname,
char *ext, size_t sz_ext )
{
const char *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 (drv)
if (drive)
{
drv[0] = inpath[0];
drv[1] = inpath[1];
drv[2] = 0;
if (sz_drive <= 2) goto error;
drive[0] = inpath[0];
drive[1] = inpath[1];
drive[2] = 0;
}
inpath += 2;
}
else if (drv) drv[0] = 0;
else if (drive) drive[0] = '\0';
/* look for end of directory part */
end = NULL;
......@@ -1892,6 +1892,7 @@ void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
{
if (dir)
{
if (sz_dir <= end - inpath) goto error;
memcpy( dir, inpath, end - inpath );
dir[end - inpath] = 0;
}
......@@ -1907,8 +1908,44 @@ void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
if (fname)
{
if (sz_fname <= end - inpath) goto error;
memcpy( fname, inpath, end - inpath );
fname[end - inpath] = 0;
}
if (ext) strcpy( ext, end );
if (ext)
{
if (sz_ext <= strlen(end)) goto error;
strcpy( 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;
}
/*********************************************************************
* _splitpath (NTDLL.@)
*
* Split a path into its component pieces.
*
* PARAMS
* inpath [I] Path to split
* drv [O] Destination for drive component (e.g. "A:"). Must be at least 3 characters.
* dir [O] Destination for directory component. Should be at least MAX_PATH characters.
* fname [O] Destination for File name component. Should be at least MAX_PATH characters.
* ext [O] Destination for file extension component. Should be at least MAX_PATH characters.
*
* RETURNS
* Nothing.
*/
void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
char* fname, char * ext )
{
_splitpath_s( inpath, drv, drv ? _MAX_DRIVE : 0, dir, dir ? _MAX_DIR : 0,
fname, fname ? _MAX_FNAME : 0, ext, ext ? _MAX_EXT : 0 );
}
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