1
0

fexecve.c 407 B

12345678910111213141516
  1. #define _GNU_SOURCE
  2. #include <unistd.h>
  3. #include <errno.h>
  4. #include <fcntl.h>
  5. #include "syscall.h"
  6. int fexecve(int fd, char *const argv[], char *const envp[])
  7. {
  8. int r = __syscall(SYS_execveat, fd, "", argv, envp, AT_EMPTY_PATH);
  9. if (r != -ENOSYS) return __syscall_ret(r);
  10. char buf[15 + 3*sizeof(int)];
  11. __procfdname(buf, fd);
  12. execve(buf, argv, envp);
  13. if (errno == ENOENT) errno = EBADF;
  14. return -1;
  15. }