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 ELF 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
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.
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
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.