View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0001992 | 1003.1(2024)/Issue8 | System Interfaces | public | 2026-07-14 16:14 | 2026-07-14 16:14 |
| Reporter | kasperk81 | Assigned To | |||
| Priority | normal | Severity | Editorial | Type | Enhancement Request |
| Status | New | Resolution | Open | ||
| Name | Kasper K. | ||||
| Organization | Independent | ||||
| User Reference | |||||
| Section | XSH 3 | ||||
| Page Number | unknown | ||||
| Line Number | unknown | ||||
| Interp Status | |||||
| Final Accepted Text | |||||
| Summary | 0001992: Add getexepath() to retrieve the absolute pathname of the current process executable image. | ||||
| Description | There 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 Action | 1. 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. | ||||
| Tags | api, enhancement, process, unistd | ||||