OpenBSD manual page server

Manual Page Search Parameters

GETEXECPATH(3) Library Functions Manual GETEXECPATH(3)

getexecpathattempt to get executable path

#include <unistd.h>

int
getexecpath(char *buf, size_t bufsize);

The () 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 () 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.

Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

The getexecpath() function will fail if:

[]
execve(2) could not determine the executable pathname.
[]
The bufsize argument is too small.

execve(2)

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.

OpenBSD-current August 31, 2026 GETEXECPATH(3)