[Previous]
[Contents]
[Next]

_splitpath2()

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

Synopsis:

#include <stdlib.h>

void _splitpath2( const char *inp,
                  char *outp, char **node,
                  char **dir, char **fname,
                  char **ext );

Description:

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

The arguments are as follows:

inp
The argument inp points to a buffer containing the full pathname to be split up.
outp
The argument outp points to a buffer that will contain all the components of the path, each separated by a null character. The maximum size required for this buffer is specified by the manifest constant _MAX_PATH2, which is defined in <stdlib.h>.
node
The node argument is the location that is to contain the pointer to the node specification (for example, //0, //1, and so on.) if a node is specified in the full pathname (filled in by _splitpath2()).
dir
The dir argument is the location that is to contain the pointer to the directory path, including the trailing slash, if a directory path is specified in the full pathname (filled in by _splitpath2()).
fname
The fname argument is the location that is to contain the pointer to the base name of the file without any extension (suffix) if a file name is specified in the full pathname (filled in by _splitpath2()).
ext
The ext argument is the location that is to contain the pointer to the filename extension (suffix) including the leading period if an extension is specified in the full pathname (filled in by _splitpath2()). 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 aren't filled in if they're NULL pointers.

For each component of the full pathname that isn't present, its corresponding pointer is set to point at a NULL string ('\0').

This function reduces the amount of memory space required when compared to the _splitpath() function.

Examples:

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

void main()
  {
    char full_path[ _MAX_PATH ];
    char tmp_path[ _MAX_PATH2 ];
    char *node;
    char *dir;
    char *fname;
    char *ext;

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

    _splitpath2( full_path, tmp_path,
         &node, &dir, &fname, &ext );
    printf( "Components after _splitpath2\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 _splitpath2
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(), _splitpath()


[Previous]
[Contents]
[Next]