[Previous] [Contents] [Next]

_cmdname()

Find the path used to invoke the current process

Synopsis:

#include <process.h>

char * _cmdname( char * buff );

Library:

libc

Description:

The _cmdname() function determines the fullpath that the current process was invoked from and stores it in the buffer specified by buff.

To determine the size of the buff argument, call fpathconf() or pathconf() with an argument of _PC_PATH_MAX.

Returns:

0
Success.
-1
An error occurred.

Examples:

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <process.h>

int main( void )
{
    size_t maximum_path;
    char *buff;
    
    maximum_path = (size_t) pathconf( "/", _PC_PATH_MAX );
    buff = (char* )malloc( maximum_path );

    if( _cmdname( buff ) ) {
        printf( "I'm \"%s\".\n", buff );
    } else {
        perror( "_cmdname() failed" );
        free (buff);
        return EXIT_FAILURE;
    }
    
    free (buff);
    return EXIT_SUCCESS;
}

If this code is compiled into an executable named foo:

# ls -F /home/xyzzy/bin/foo
foo*
# /home/xyzzy/bin/foo
I'm "/home/xyzzy/bin/foo".

Classification:

QNX 4

Safety:
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes

See also:

basename(), _cmdfd()


[Previous] [Contents] [Next]