From bc2a115b556d19b79e29b8b094ec3d153ed7c6d3 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Wed, 2 Jan 2019 23:56:42 +0100 Subject: [PATCH] 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. --- build-aux/check-mescc.sh | 1 + build-aux/configure-lib.sh | 1 + include/unistd.h | 1 + lib/posix/execl.c | 32 ++++++++++++++-------- lib/posix/execlp.c | 47 ++++++++++++++++++++++++++++++++ lib/tests/posix/90-execlp.c | 28 +++++++++++++++++++ lib/tests/posix/90-execlp.stdout | 1 + 7 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 lib/posix/execlp.c create mode 100644 lib/tests/posix/90-execlp.c create mode 100644 lib/tests/posix/90-execlp.stdout diff --git a/build-aux/check-mescc.sh b/build-aux/check-mescc.sh index 84158697..b688b40f 100755 --- a/build-aux/check-mescc.sh +++ b/build-aux/check-mescc.sh @@ -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 diff --git a/build-aux/configure-lib.sh b/build-aux/configure-lib.sh index 1dfe84fd..b821b29e 100644 --- a/build-aux/configure-lib.sh +++ b/build-aux/configure-lib.sh @@ -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 diff --git a/include/unistd.h b/include/unistd.h index 44792f90..53c68561 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -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); diff --git a/lib/posix/execl.c b/lib/posix/execl.c index ae651510..45135864 100644 --- a/lib/posix/execl.c +++ b/lib/posix/execl.c @@ -23,22 +23,13 @@ #include 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 *); + argv[i++] = (char *) file_name; 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; +} diff --git a/lib/posix/execlp.c b/lib/posix/execlp.c new file mode 100644 index 00000000..48a239ae --- /dev/null +++ b/lib/posix/execlp.c @@ -0,0 +1,47 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +#include +#include +#include + +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; +} diff --git a/lib/tests/posix/90-execlp.c b/lib/tests/posix/90-execlp.c new file mode 100644 index 00000000..450575b2 --- /dev/null +++ b/lib/tests/posix/90-execlp.c @@ -0,0 +1,28 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +#include "unistd.h" + +int +main (int argc, char const *argv[]) +{ + execlp ("echo", "echo", "Hello", "World!", 0); + return 0; +} diff --git a/lib/tests/posix/90-execlp.stdout b/lib/tests/posix/90-execlp.stdout new file mode 100644 index 00000000..980a0d5f --- /dev/null +++ b/lib/tests/posix/90-execlp.stdout @@ -0,0 +1 @@ +Hello World!