blob: ff97bff13ac341e1e6d1d3b826aef0ee28f17eb1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
|