diff --git a/build-aux/check-mescc.sh b/build-aux/check-mescc.sh index 9495e2de..d19bbdf6 100755 --- a/build-aux/check-mescc.sh +++ b/build-aux/check-mescc.sh @@ -192,6 +192,7 @@ scaffold/tests/84-struct-field-list scaffold/tests/85-sizeof lib/tests/dirent/90-readdir lib/tests/io/90-stat +lib/tests/posix/90-execlp lib/tests/posix/90-unsetenv lib/tests/signal/90-signal lib/tests/stdio/90-fopen diff --git a/include/unistd.h b/include/unistd.h index 8810cbf4..a5c840f8 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/libc+gnu.c b/lib/libc+gnu.c index e9095a19..c1233520 100644 --- a/lib/libc+gnu.c +++ b/lib/libc+gnu.c @@ -119,3 +119,6 @@ #include #include #include + +// tar +#include diff --git a/lib/posix/execl.c b/lib/posix/execl.c index 2142acde..9ef07dd6 100644 --- a/lib/posix/execl.c +++ b/lib/posix/execl.c @@ -22,20 +22,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 const *); char *argv[1000]; // POSIX minimum 4096 int i = 0; - va_list ap; - va_start (ap, arg); - argv[i++] = file_name; - arg = va_arg (ap, char const *); while (arg) { argv[i++] = arg; @@ -50,3 +43,18 @@ 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..aa296eb9 --- /dev/null +++ b/lib/posix/execlp.c @@ -0,0 +1,44 @@ +/* -*-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 + +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!