blob: ff97bff13ac341e1e6d1d3b826aef0ee28f17eb1 (
plain) (
tree)
|
|
/* 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
|