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.
* 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:
Jan Nieuwenhuizen 2019-01-02 23:56:42 +01:00
parent ecf9220bbc
commit f39e1cc250
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
7 changed files with 95 additions and 9 deletions

View File

@ -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

View File

@ -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);

View File

@ -119,3 +119,6 @@
#include <stub/rand.c>
#include <stub/sigdelset.c>
#include <stub/ttyname.c>
// tar
#include <posix/execlp.c>

View File

@ -22,20 +22,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 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;
}

44
lib/posix/execlp.c Normal file
View File

@ -0,0 +1,44 @@
/* -*-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 <libmes.h>
#include <unistd.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;
}

View 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;
}

View File

@ -0,0 +1 @@
Hello World!