-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecle.c
47 lines (37 loc) · 838 Bytes
/
execle.c
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
/*
* Copyright 2021-2024 Gaël PORTAY
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <errno.h>
#include <limits.h>
#include <unistd.h>
#include "iamroot.h"
int execle(const char *path, const char *arg, ...)
{
va_list ap;
int argc;
argc = 1;
va_start(ap, arg);
while (va_arg(ap, const char *))
argc++;
va_end(ap);
if (argc < ARG_MAX) {
char **envp, *argv[argc+1]; /* NULL-terminated */
int i;
argv[0] = (char *)arg;
va_start(ap, arg);
for (i = 1; i <= argc; i++)
argv[i] = va_arg(ap, char *);
envp = va_arg(ap, char **);
va_end(ap);
__debug("%s(path: '%s', arg: '%s', ..., envp: %p)\n", __func__,
path, arg, envp);
/* Forward to another function */
return execve(path, argv, envp);
}
return __set_errno(E2BIG, -1);
}