Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/c/_cmdname.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/c/_cmdname.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/c/_cmdname.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/c/_cmdname.html on line 8

_cmdname()

Find the path used to invoke the current process

Synopsis:

#include <process.h>

char * _cmdname( char * buff );

Arguments:

buff
NULL, or a pointer to a buffer in which the function can store the path. To determine the size required for the buffer, call fpathconf() or pathconf() with an argument of _PC_PATH_MAX, then add 1 for the terminating null character.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The _cmdname() function determines the full path that the current process was invoked from. If buff isn't NULL, _cmdname() copies the path into the buffer that buff points to.

Returns:

A pointer to the pathname used to load the process, or NULL if an error occurred.


Note: Don't change the string that the returned value points to if you passed NULL for the buff parameter.

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(), __progname


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/c/_cmdname.html on line 171

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/c/_cmdname.html on line 171