GETEXECPATH(3)

NAME
getexecpath - attempt to get executable path

SYNOPSIS
#include <unistd.h>
int
getexecpath(char *buf, size_t bufsize);

DESCRIPTION
The getexecpath() function retrieves the absolute pathname of this executable. If the pathname is shorter than bufsize bytes, it is copied into the memory referenced by buf. The recommended buffer size is PATH_MAX. This pathname has been canonicalized in the same manner as realpath(3).

The two main reasons why getexecpath() can return failure are if the executable was started in a directory which is no longer linked to the filesystem, or if the absolute pathname would exceed PATH_MAX.

RETURN VALUES

ERRORS
The getexecpath() function will fail if:

[ENOENT]
    execve(2) could not determine the executable pathname.

[ERANGE]
    The bufsize argument is too small.

SEE ALSO
execve(2)

HISTORY
The getexecpath() function first appeared in OpenBSD 8.0. A variety of system-dependent (and often flawed) solutions for this problem of retrieving the executable path are available in other operating systems. getexecpath() aspires to do better.