_makepath, _wmakepath
Create a path name from components.
void _makepath( char *path, const char *drive, const char *dir, const char *fname, const char *ext ); void _wmakepath( wchar_t *path, const wchar_t *drive, const wchar_t *dir, const wchar_t *fname, const wchar_t *ext );
Parameters
- path
- Full path buffer. _makepath does not check that path does not exceed _MAX_PATH.
- drive
- Drive letter.
- dir
- Directory path.
- fname
- Filename.
- ext
- File extension.
Remarks
The _makepath function creates a single path and stores it in path. The path may include a drive letter, directory path, filename, and filename extension. _wmakepath is a wide-character version of _makepath; the arguments to _wmakepath are wide-character strings. _wmakepath and _makepath behave identically otherwise.
Security Note Use a null-terminated string. The null-terminated string must not exceed the size of the destination buffer. For more information, see Avoiding Buffer Overruns.
Generic-Text Routine Mappings
| TCHAR.H routine | _UNICODE & _MBCS not defined | _MBCS defined | _UNICODE defined |
|---|---|---|---|
| _tmakepath | _makepath | _makepath | _wmakepath |
The following arguments point to buffers containing the path elements:
- drive
- Contains a letter (A, B, and so on) corresponding to the desired drive and an optional trailing colon. _makepath inserts the colon automatically in the composite path if it is missing. If drive is a null character or an empty string, no drive letter and colon appear in the composite path string.
- dir
- Contains the path of directories, not including the drive designator or the actual filename. The trailing slash is optional, and either a forward slash (/) or a backslash (\) or both may be used in a single dir argument. If a trailing slash (/ or \) is not specified, it is inserted automatically. If dir is a null character or an empty string, no slash is inserted in the composite path string.
- fname
- Contains the base filename without any extensions. If fname is NULL or points to an empty string, no filename is inserted in the composite path string.
- ext
- Contains the actual filename extension, with or without a leading period (.). _makepath inserts the period automatically if it does not appear in ext. If ext is a null character or an empty string, no period is inserted in the composite path string.
The path argument must point to an empty buffer large enough to hold the complete path. Although there are no size limits on any of the fields that constitute path, the composite path must be no larger than the _MAX_PATH constant, defined in STDLIB.H. _MAX_PATH may be larger than the current operating-system version will handle.
Requirements
| Routine | Required header | Compatibility |
|---|---|---|
| _makepath | <stdlib.h> | Win 98, Win Me, Win NT, Win 2000, Win XP |
| _wmakepath | <stdlib.h> or <wchar.h> | Win 98, Win Me, Win NT, Win 2000, Win XP |
For additional compatibility information, see Compatibility in the Introduction.
Libraries
All versions of the C run-time libraries.
Example
// crt_makepath.c
#include <stdlib.h>
#include <stdio.h>
int main( void )
{
char path_buffer[_MAX_PATH];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_makepath( path_buffer, "c", "\\sample\\crt\\", "makepath", "c" );
printf( "Path created with _makepath: %s\n\n", path_buffer );
_splitpath( path_buffer, drive, dir, fname, ext );
printf( "Path extracted with _splitpath:\n" );
printf( " Drive: %s\n", drive );
printf( " Dir: %s\n", dir );
printf( " Filename: %s\n", fname );
printf( " Ext: %s\n", ext );
}
Output
Path created with _makepath: c:\sample\crt\makepath.c Path extracted with _splitpath: Drive: c: Dir: \sample\crt\ Filename: makepath Ext: .c
See Also
File Handling Routines | _fullpath | _splitpath | Run-Time Routines and .NET Framework Equivalents