aboutsummaryrefslogblamecommitdiffstats
path: root/libexec_openat2.c
blob: 417a7e55457e8f147ea144574cc59b6366d31344 (plain) (tree)
1
2
3
4
5
6
7





                                                         
                                                                                                                    














































                                                          
/* 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