_makepath -- Create Path

Format

#include <stdlib.h>
void _makepath(char *path, char *drive, char *dir,
                 char *fname, char *ext);

Language Level: Extension
_makepath creates a single path name, composed of a drive letter, directory path, file name, and file name extension.

The path argument should point to an empty buffer large enough to hold the complete path name. The constant _MAX_PATH, defined in <stdlib.h>, specifies the maximum size allowed for path. The other arguments point to the following buffers containing the path name elements:

drive A letter (A, B, ...) corresponding to the desired drive and an optional following colon. _makepath inserts the colon automatically in the composite path name if it is missing. If drive is a null character or an empty string, no drive letter or colon appears in the composite path string.
dir The path of directories, not including the drive designator or the actual file name. The trailing slash is optional, and either slash (/) or backslash (\) or both can be used in a single dir argument. If a trailing slash or backslash 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 The base file name without any extensions.
ext The actual file name 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 size limits on the above four fields are those specified by the constants _MAX_DRIVE, _MAX_DIR, _MAX_FNAME, and _MAX_EXT, which are defined in <stdlib.h>. The composite path should be no larger than the _MAX_PATH constant also defined in <stdlib.h>; otherwise, the operating system does not handle it correctly.

Note: No checking is done to see if the syntax of the file name is correct.

Return Value
There is no return value.

Example
This example builds a file name path from the specified components.

#include <stdio.h>
#include <stdlib.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", "qc\\bob\\eclibref\\e", "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("directory: %s\n", dir);
   printf("file name: %s\n", fname);
   printf("extension: %s\n", ext);
   return 0;
   /********************************************************************
      The output should be:
      Path created with _makepath: c:qc\bob\eclibref\e\makepath.c
      Path extracted with _splitpath:
      drive: c:
      directory: qc\bob\eclibref\e\
      filename: makepath
      extension: .c
   ********************************************************************/
}



_fullpath -- Get Full Path Name of Partial Path
_splitpath -- Decompose Path Name
<stdlib.h>