diff options
Diffstat (limited to '')
-rw-r--r-- | libexec_openat2.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/libexec_openat2.c b/libexec_openat2.c new file mode 100644 index 0000000..ff97bff --- /dev/null +++ b/libexec_openat2.c @@ -0,0 +1,54 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +int +libexec_openat2(struct libexec_command *cmd, int fd, int dirfd, const char *file, struct open_how *how, size_t size) +{ +#if defined(__linux__) + + struct libexec_pluming pluming; + if (fd < 0) { + errno = EINVAL; + return -1; + } + memset(&pluming, 0, sizeof(pluming)); + pluming.fd = fd; + pluming.type = LIBEXEC_PLUMING_OPENAT2; + pluming.target.dirfd = dirfd; + pluming.target.how = NULL; + pluming.target.file = NULL; + if (file) { + pluming.target.file = strdup(file); + if (!pluming.target.file) + return -1; + } + if (size) { + pluming.target.how = malloc(size); + if (!pluming.target.how) { + free(pluming.target.file); + return -1; + } + memcpy(pluming.target.how, how, size); + pluming.target.how_size = size; + } + if (libexec_add_pluming(cmd, &pluming)) { + free(pluming.target.file); + free(pluming.target.how); + return -1; + } + return 0; + +#else + + errno = ENOSYS; + return -1; + +#endif +} + + +#else +LIBEXEC_CONST__ int main(void) {return 0;} /* TODO test */ +#endif |