_splitpath、_wsplitpath_splitpath, _wsplitpath

将路径名称分解成组件。Break a path name into components. 提供这些函数的更多安全版本;请参阅 _splitpath_s、_wsplitpath_sMore secure versions of these functions are available, see _splitpath_s, _wsplitpath_s.


void _splitpath(  
   const char *path,  
   char *drive,  
   char *dir,  
   char *fname,  
   char *ext   
void _wsplitpath(  
   const wchar_t *path,  
   wchar_t *drive,  
   wchar_t *dir,  
   wchar_t *fname,  
   wchar_t *ext   


完整路径。Full path.

后跟一个冒号 (:) 的驱动器号。Drive letter, followed by a colon (:). 如果不需要驱动器号,则可为此参数传递 NULLYou can pass NULL for this parameter if you do not need the drive letter.

目录路径,包括尾部反斜杠。Directory path, including trailing slash. 正斜杠 ( / )、反斜杠 ( \ ),或两者均使用。Forward slashes ( / ), backslashes ( \ ), or both may be used. 如果不需要目录路径,则可为此参数传递 NULLYou can pass NULL for this parameter if you do not need the directory path.

基文件名(无扩展名)。Base filename (no extension). 如果不需要文件名,则可为此参数传递 NULLYou can pass NULL for this parameter if you do not need the filename.

文件扩展名,包括前导句点 (.)。Filename extension, including leading period (.). 如果不需要文件扩展名,则可为此参数传递 NULLYou can pass NULL for this parameter if you do not need the filename extension.


_splitpath 函数将路径分解成其的四个组件。The _splitpath function breaks a path into its four components. _splitpath 将根据情况自动处理多字节字符串参数,根据当前正在使用的多字节代码页识别多字节字符序列。_splitpath automatically handles multibyte-character string arguments as appropriate, recognizing multibyte-character sequences according to the multibyte code page currently in use. _wsplitpath_splitpath 的宽字符版本;_wsplitpath 的参数是宽字符串。_wsplitpath is a wide-character version of _splitpath; the arguments to _wsplitpath are wide-character strings. 否则这些函数具有相同行为。These functions behave identically otherwise.

安全说明这些函数会引发由缓冲区溢出问题带来的潜在威胁。Security Note These functions incur a potential threat brought about by a buffer overrun problem. 缓冲区溢出问题是常见的系统攻击方法,使权限的提升不能确保。Buffer overrun problems are a frequent method of system attack, resulting in an unwarranted elevation of privilege. 有关详细信息,请参阅 避免缓冲区溢出For more information, see Avoiding Buffer Overruns. 提供这些函数的更多安全版本;请参阅 _splitpath_s、_wsplitpath_sMore secure versions of these functions are available; see _splitpath_s, _wsplitpath_s.

一般文本例程映射Generic-Text Routine Mappings

TCHAR.H 例程TCHAR.H routine 未定义 _UNICODE 和 _MBCS_UNICODE & _MBCS not defined 已定义 _MBCS_MBCS defined 已定义 _UNICODE_UNICODE defined
_tsplitpath _splitpath _splitpath _wsplitpath

完整路径的每个组件均存储在单独的缓冲区中;清单常量 _MAX_DRIVE_MAX_DIR_MAX_FNAME_MAX_EXT(在 STDLIB.H 中定义)指定每个文件组件的最大大小。Each component of the full path is stored in a separate buffer; the manifest constants _MAX_DRIVE, _MAX_DIR, _MAX_FNAME, and _MAX_EXT (defined in STDLIB.H) specify the maximum size for each file component. 文件组件大于相应清单常量会导致堆损坏。File components that are larger than the corresponding manifest constants cause heap corruption.

每个缓冲区必须与其相应的清单常量一样大,以避免潜在的缓冲区溢出。Each buffer must be as large as its corresponding manifest constant to avoid potential buffer overrun.

下表列出了清单常量的值。The following table lists the values of the manifest constants.

nameName “值”Value

如果完整路径不包含组件(例如,文件名),则 _splitpath 会将空字符串分配给相应的缓冲区。If the full path does not contain a component (for example, a filename), _splitpath assigns empty strings to the corresponding buffers.

可以为除不需要的 path 以外的任何参数将 NULL 传递到 _splitpathYou can pass NULL to _splitpath for any parameter other than path that you do not need.

如果 pathNULL,则将调用无效的参数处理程序,如参数验证中所述。If path is NULL, the invalid parameter handler is invoked, as described in Parameter Validation. 如果允许继续执行,则将 errno 设置为 EINVAL 并且该函数将返回 EINVALIf execution is allowed to continue, errno is set to EINVAL and the function returns EINVAL.


例程所返回的值Routine 必需的标头Required header
_splitpath <stdlib.h><stdlib.h>
_wsplitpath <stdlib.h> 或 <wchar.h><stdlib.h> or <wchar.h>

有关其他兼容性信息,请参见“简介”中的 兼容性For additional compatibility information, see Compatibility in the Introduction.


请参阅 _makepath 的示例。See the example for _makepath.

请参阅See Also

文件处理 File Handling
_fullpath、_wfullpath _fullpath, _wfullpath
_getmbcp _getmbcp
_makepath、_wmakepath _makepath, _wmakepath
_setmbcp _setmbcp
_splitpath_s、_wsplitpath_s_splitpath_s, _wsplitpath_s