[Previous]
[Contents]
[Next]

_splitpath()

split a pathname into node, directory, file name, and extension

Synopsis:

#include <stdlib.h>

void _splitpath( const char *path,
                 char *node, char *dir,
                 char *fname, char *ext );

Description:

The _splitpath() function splits up a full pathname into four components, consisting of:

The argument path points to a buffer containing the full pathname to be split up.

The maximum size required for each buffer is specified by the manifest constants _MAX_PATH, _MAX_NODE, _MAX_DIR, _MAX_FNAME, and _MAX_EXT, which are defined in <stdlib.h>.

node
The node argument points to a buffer that's filled in with the node specification (for example, //0, //1, and so on) if a node is specified in the full pathname.
dir
The dir argument points to a buffer that's filled in with the pathname, including the trailing slash.
fname
The fname argument points to a buffer that's filled in with the base name of the file without any extension (suffix) if a file name is specified in the full pathname (filled in by _splitpath()).
ext
The ext argument points to a buffer that's filled in with the filename extension (suffix) including the leading period if an extension is specified in the full pathname (filled in by _splitpath()). If more than one period appears in the filename, the suffix consists of the final period and characters following it. If ext is a NULL pointer, then the extension or suffix is included with the file name.

The arguments node, dir, fname and ext will not be filled in if they're NULL pointers.

For each component of the full pathname that isn't present, its corresponding buffer is set to an empty string.

Examples:

#include <stdio.h>
#include <stdlib.h>

void main()
  {
    char full_path[ _MAX_PATH ];
    char node[ _MAX_NODE ];
    char dir[ _MAX_DIR ];
    char fname[ _MAX_FNAME ];
    char ext[ _MAX_EXT ];

    _makepath(full_path,"//0","/home/fred/h","stdio","h");
    printf( "Full path is: %s\n\n", full_path );

    _splitpath( full_path, node, dir, fname, ext );
    printf( "Components after _splitpath\n" );
    printf( "node:  %s\n", node );
    printf( "dir:   %s\n", dir );
    printf( "fname: %s\n", fname );
    printf( "ext:   %s\n", ext );
  }

produces the output:

Full path is: //0/home/fred/h/stdio.h

Components after _splitpath
node:  //0
dir:   /home/fred/h/
fname: stdio
ext:   .h

Classification:

WATCOM

Safety:
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

_fullpath(), _makepath(), _splitpath2()


[Previous]
[Contents]
[Next]