View Issue Details

IDProjectCategoryView StatusLast Update
00019921003.1(2024)/Issue8System Interfacespublic2026-07-14 16:14
Reporterkasperk81 Assigned To 
PrioritynormalSeverityEditorialTypeEnhancement Request
Status NewResolutionOpen 
NameKasper K.
OrganizationIndependent
User Reference
SectionXSH 3
Page Numberunknown
Line Numberunknown
Interp Status
Final Accepted Text
Summary0001992: Add getexepath() to retrieve the absolute pathname of the current process executable image.
DescriptionThere is currently no standardized, portable mechanism in POSIX to retrieve the absolute pathname of the executable file currently executing the calling process. Runtimes, language interpreters, and asset loaders must resort to highly unportable, platform-specific mechanisms.

- Linux relies on parsing the "/proc/self/exe" symlink or using `getauxval(AT_EXECFN)`.
- FreeBSD and NetBSD use a sysctl interface via KERN_PROC_PATHNAME.
- SunOS implements getexecname().
- macOS implements a non-POSIX _NSGetExecutablePath() function.

Others like OpenBSD force us to rely on argv[0] and (if the process didn't start with an absolute path) scanning the PATH environment variable, which is fundamentally unsafe and unreliable (someone else in the PATH with the same name appearing early is picked up). Furthermore, the parent process can easily manipulate or empty argv and envp during an execve() call, leaving the child completely unable to safely determine its own physical location.

Adding a native, safe API to POSIX eliminates immense cross-platform boilerplate across programming frameworks and toolchains that require explicit binary path auditing.
Desired Action1. In <unistd.h>, add the following function prototype:

   ssize_t getexepath(char *buf, size_t bufsize);

2. Add a new manual page under Section 3 (FUNCTIONS) detailing the specification:

NAME
    getexepath — get the absolute pathname of the executing process image.

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

DESCRIPTION
    The getexepath() function shall copy an absolute pathname of the executable file associated with the current process into the buffer pointed to by buf, which has a size of bufsize.

    If the actual length of the pathname (including the terminating null byte) is greater than bufsize, the string shall be truncated to bufsize - 1 bytes and null-terminated.

RETURN VALUE
    Upon successful completion, getexepath() shall return the number of bytes required to hold the full, non-truncated path (excluding the terminating null byte). If an error occurs, -1 shall be returned and errno set to indicate the error.

ERRORS
    The getexepath() function shall fail if:
    [EINVAL] - The buf argument is a null pointer.
    [ENOENT] - The executable file has been unlinked from the filesystem and the system cannot resolve its original path.
Tagsapi, enhancement, process, unistd

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2026-07-14 16:14 kasperk81 New Issue
2026-07-14 16:14 kasperk81 Tag Attached: api
2026-07-14 16:14 kasperk81 Tag Attached: enhancement
2026-07-14 16:14 kasperk81 Tag Attached: process
2026-07-14 16:14 kasperk81 Tag Attached: unistd