From 40e2986d3d196855bba3836a60a482fd3a0f73a8 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Wed, 31 Jan 2024 17:07:29 -0500 Subject: remove posix and xopen specific functions --- src/stdio/popen.c | 71 ------------------------------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 src/stdio/popen.c (limited to 'src/stdio/popen.c') diff --git a/src/stdio/popen.c b/src/stdio/popen.c deleted file mode 100644 index 67b70f4d..00000000 --- a/src/stdio/popen.c +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include -#include - -#include -#include -#endif - -FILE * popen(const char * command, const char * mode) -{ - SIGNAL_SAFE(0); - ASSERT_NONNULL(command); - ASSERT_NONNULL(mode); - - int direction = 0; - if (!strcmp(mode, "w")) { - direction = 1; - } else if (strcmp(mode, "r")) { - errno = EINVAL; - return NULL; - } - - int pd[2]; - if (pipe(pd) == -1) { - return NULL; - } - - pid_t child = fork(); - if (child == -1) { - close(pd[0]); - close(pd[1]); - return NULL; - } else if (child == 0) { - if (direction == 1) { - dup2(pd[0], STDIN_FILENO); - } else { - dup2(pd[1], STDOUT_FILENO); - } - close(pd[0]); - close(pd[1]); - execl("/bin/sh", "sh", "-c", command, (char *)0); - return NULL; - } - - FILE *p = NULL; - if (direction == 1) { - p = fdopen(pd[1], "w"); - } else { - p = fdopen(pd[0], "r"); - } - - if (p == NULL) { - return NULL; - } - - #if defined __STDC_VERSION__ - fwide(p, -1); - #endif - - p->pipe_pid = child; - return p; -} - -/* -POSIX(2) -*/ -- cgit v1.2.1