-
Notifications
You must be signed in to change notification settings - Fork 0
/
execlp.c
50 lines (40 loc) · 849 Bytes
/
execlp.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
48
49
50
/*
* 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 execlp(const char *file, 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(file: '%s', arg: '%s', ...)\n", __func__, file,
arg);
/* Forward to another function */
#ifdef __linux__
return execvpe(file, argv, __environ);
#else
return execvp(file, argv);
#endif
}
return __set_errno(E2BIG, -1);
}