From f999e30afddcb539fbe50fde059db523795fb099 Mon Sep 17 00:00:00 2001 From: Brandon Scott Date: Sat, 16 Nov 2019 02:35:48 -0600 Subject: [PATCH] LibC: Added execlp method and new pathconf setting Added execlp method, and _PC_PIPE_BUF setting to pathconf method. --- Libraries/LibC/limits.h | 1 + Libraries/LibC/unistd.cpp | 23 +++++++++++++++++++++-- Libraries/LibC/unistd.h | 11 ++++++----- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Libraries/LibC/limits.h b/Libraries/LibC/limits.h index 08d8148381..1c5f583556 100644 --- a/Libraries/LibC/limits.h +++ b/Libraries/LibC/limits.h @@ -8,6 +8,7 @@ #if !defined MAXPATHLEN && defined PATH_MAX # define MAXPATHLEN PATH_MAX #endif +#define PIPE_BUF 4096 #define INT_MAX INT32_MAX #define INT_MIN INT32_MIN diff --git a/Libraries/LibC/unistd.cpp b/Libraries/LibC/unistd.cpp index c935b27769..0bfb109192 100644 --- a/Libraries/LibC/unistd.cpp +++ b/Libraries/LibC/unistd.cpp @@ -104,6 +104,24 @@ int execl(const char* filename, const char* arg0, ...) return execve(filename, const_cast(args.data()), environ); } +int execlp(const char* filename, const char* arg0, ...) +{ + Vector args; + args.append(arg0); + + va_list ap; + va_start(ap, arg0); + for (;;) { + const char* arg = va_arg(ap, const char*); + if (!arg) + break; + args.append(arg); + } + va_end(ap); + args.append(nullptr); + return execvpe(filename, const_cast(args.data()), environ); +} + uid_t getuid() { return syscall(SC_getuid); @@ -459,11 +477,12 @@ long fpathconf(int fd, int name) long pathconf(const char* path, int name) { (void)path; - (void)name; switch (name) { case _PC_PATH_MAX: return PATH_MAX; + case _PC_PIPE_BUF: + return PIPE_BUF; } ASSERT_NOT_REACHED(); @@ -548,7 +567,7 @@ char* getlogin() return nullptr; } -int create_thread(void *(*entry)(void*), void* argument) +int create_thread(void* (*entry)(void*), void* argument) { int rc = syscall(SC_create_thread, entry, argument); __RETURN_WITH_ERRNO(rc, rc, -1); diff --git a/Libraries/LibC/unistd.h b/Libraries/LibC/unistd.h index 7c64ac3de9..b112a31263 100644 --- a/Libraries/LibC/unistd.h +++ b/Libraries/LibC/unistd.h @@ -20,13 +20,12 @@ __BEGIN_DECLS #define STDERR_FILENO 2 /* lseek whence values */ -#ifndef _STDIO_H /* also defined in stdio.h */ -#define SEEK_SET 0 /* from beginning of file. */ -#define SEEK_CUR 1 /* from current position in file. */ -#define SEEK_END 2 /* from the end of the file. */ +#ifndef _STDIO_H /* also defined in stdio.h */ +# define SEEK_SET 0 /* from beginning of file. */ +# define SEEK_CUR 1 /* from current position in file. */ +# define SEEK_END 2 /* from the end of the file. */ #endif - extern char** environ; int get_process_name(char* buffer, int buffer_size); @@ -54,6 +53,7 @@ int execve(const char* filename, char* const argv[], char* const envp[]); int execvpe(const char* filename, char* const argv[], char* const envp[]); int execvp(const char* filename, char* const argv[]); int execl(const char* filename, const char* arg, ...); +int execlp(const char* filename, const char* arg, ...); void sync(); void _exit(int status); pid_t getsid(pid_t); @@ -127,6 +127,7 @@ char* realpath(const char* pathname, char* buffer); enum { _PC_NAME_MAX, _PC_PATH_MAX, + _PC_PIPE_BUF }; #define HOST_NAME_MAX 64