From edd1b873f2a8b356ff2ff557e7b0e9497e404f38 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 1 Jan 2016 17:44:57 +0100 Subject: portability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- TODO | 3 +++ src/unistd/fexec.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index ffe907c..e276d42 100644 --- a/TODO +++ b/TODO @@ -69,3 +69,6 @@ resulting string to 32765 bytes! Can we implement any of these: http://www.gnu.org/fun/jokes/errno.2 +Macros that are used but not defined: + _LINUX_ + diff --git a/src/unistd/fexec.c b/src/unistd/fexec.c index 2f2b229..36352ce 100644 --- a/src/unistd/fexec.c +++ b/src/unistd/fexec.c @@ -186,15 +186,21 @@ int fexecv(int fd, char* const argv[]) */ int fexecve(int fd, char* const argv[], char* const envp[]) { - char pathname[sizeof("/proc/self/fd//") + 3 * sizeof(int)]; +#if defined(_LINUX_) +# define FD_PATH "/proc/self/fd" /* /dev/fd works but it is a symbolic link. */ +#else +# define FD_PATH "/dev/fd" +#endif + + char pathname[sizeof(FD_PATH "//") + 3 * sizeof(int)]; int saved_errno; - sprintf(pathname, "/proc/self/fd/%i/", fd); + sprintf(pathname, FD_PATH "/%i/", fd); execve(pathname, argv, envp); saved_errno = errno; - if (access("/proc/", X_OK)) + if (access(FD_PATH "/", X_OK)) saved_errno = ENOSYS; errno = saved_errno == ENOENT ? EBADF : saved_errno; -- cgit v1.2.3-70-g09d2