mescc: Mes C Library: Support GNU Tar: Add execlp.
* lib/posix/execl.c (vexec): New function. (execl): Use it. * lib/posix/execlp.c: New file. * build-aux/configure-lib.sh (libc_tcc_SOURCES): Add it. * lib/libc+gnu.c: Include it. * include/unistd.h (execlp): Declare. * lib/tests/posix/90-execlp.c: New file. * lib/tests/posix/90-execlp.stdout: New file. * build-aux/check-mescc.sh: Test it.
This commit is contained in:
parent
18195b4d05
commit
4e6a3ce846
|
@ -200,6 +200,7 @@ if test -z "$bootstrap"; then
|
|||
TESTS="$TESTS
|
||||
lib/tests/dirent/90-readdir.c
|
||||
lib/tests/io/90-stat.c
|
||||
lib/tests/posix/90-execlp.c
|
||||
lib/tests/posix/90-unsetenv.c
|
||||
lib/tests/signal/90-signal.c
|
||||
lib/tests/stdio/90-fopen.c
|
||||
|
|
|
@ -227,6 +227,7 @@ lib/math/fabs.c
|
|||
lib/mes/fdgets.c
|
||||
lib/posix/alarm.c
|
||||
lib/posix/execl.c
|
||||
lib/posix/execlp.c
|
||||
lib/posix/mktemp.c
|
||||
lib/posix/raise.c
|
||||
lib/posix/sbrk.c
|
||||
|
|
|
@ -62,6 +62,7 @@ unsigned int alarm (unsigned int seconds);
|
|||
int close (int fd);
|
||||
int execv (char const *file_name, char *const argv[]);
|
||||
int execl (char const *file_name, char const *arg, ...);
|
||||
int execlp (char const *file_name, char const *arg, ...);
|
||||
int execve (char const *file, char *const argv[], char *const env[]);
|
||||
int execvp (char const *file, char *const argv[]);
|
||||
int fork (void);
|
||||
|
|
|
@ -23,22 +23,13 @@
|
|||
#include <unistd.h>
|
||||
|
||||
int
|
||||
execl (char const *file_name, char const *arg, ...)
|
||||
vexec (char const *file_name, va_list ap)
|
||||
{
|
||||
if (__mes_debug () > 2)
|
||||
{
|
||||
eputs ("execl ");
|
||||
eputs (file_name);
|
||||
eputs ("\n");
|
||||
}
|
||||
char *arg = va_arg (ap, char *);
|
||||
char *argv[1000]; // POSIX minimum 4096
|
||||
int i = 0;
|
||||
|
||||
va_list ap;
|
||||
va_start (ap, arg);
|
||||
|
||||
argv[i++] = (char *) file_name;
|
||||
arg = (char *) va_arg (ap, char const *);
|
||||
while (arg)
|
||||
{
|
||||
argv[i++] = arg;
|
||||
|
@ -57,3 +48,20 @@ execl (char const *file_name, char const *arg, ...)
|
|||
va_end (ap);
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
execl (char const *file_name, char const *arg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int r;
|
||||
va_start (ap, arg);
|
||||
if (__mes_debug () > 2)
|
||||
{
|
||||
eputs ("execl ");
|
||||
eputs (file_name);
|
||||
eputs ("\n");
|
||||
}
|
||||
r = vexec (file_name, ap);
|
||||
va_end (ap);
|
||||
return r;
|
||||
}
|
||||
|
|
47
lib/posix/execlp.c
Normal file
47
lib/posix/execlp.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* GNU Mes is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mes/lib.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int
|
||||
execlp (char const *file_name, char const *arg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int r;
|
||||
va_start (ap, arg);
|
||||
if (file_name[0] != '/')
|
||||
file_name = search_path (file_name);
|
||||
if (__mes_debug () > 2)
|
||||
{
|
||||
eputs ("execlp ");
|
||||
eputs (file_name ? file_name : "0");
|
||||
eputs ("\n");
|
||||
}
|
||||
if (!file_name)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
r = vexec (file_name, ap);
|
||||
va_end (ap);
|
||||
return r;
|
||||
}
|
28
lib/tests/posix/90-execlp.c
Normal file
28
lib/tests/posix/90-execlp.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* GNU Mes is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "unistd.h"
|
||||
|
||||
int
|
||||
main (int argc, char const *argv[])
|
||||
{
|
||||
execlp ("echo", "echo", "Hello", "World!", 0);
|
||||
return 0;
|
||||
}
|
1
lib/tests/posix/90-execlp.stdout
Normal file
1
lib/tests/posix/90-execlp.stdout
Normal file
|
@ -0,0 +1 @@
|
|||
Hello World!
|
Loading…
Reference in a new issue