Quellcode durchsuchen

LibC: Added execlp method and new pathconf setting

Added execlp method, and _PC_PIPE_BUF setting to pathconf method.
Brandon Scott vor 5 Jahren
Ursprung
Commit
f999e30afd
3 geänderte Dateien mit 28 neuen und 7 gelöschten Zeilen
  1. 1 0
      Libraries/LibC/limits.h
  2. 21 2
      Libraries/LibC/unistd.cpp
  3. 6 5
      Libraries/LibC/unistd.h

+ 1 - 0
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

+ 21 - 2
Libraries/LibC/unistd.cpp

@@ -104,6 +104,24 @@ int execl(const char* filename, const char* arg0, ...)
     return execve(filename, const_cast<char* const*>(args.data()), environ);
 }
 
+int execlp(const char* filename, const char* arg0, ...)
+{
+    Vector<const char*, 16> 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<char* const*>(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);

+ 6 - 5
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