-
Notifications
You must be signed in to change notification settings - Fork 0
/
execl.c
46 lines (36 loc) · 788 Bytes
/
execl.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
/*
* 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 execl(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 *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 *);
va_end(ap);
__debug("%s(path: '%s', arg: '%s', ...)\n", __func__, path,
arg);
/* Forward to another function */
return execve(path, argv, __environ);
}
return __set_errno(E2BIG, -1);
}