From e7e70a9f4878848efcbf91572c30d27b8a503984 Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Tue, 1 Nov 2022 19:52:53 +0100 Subject: [PATCH] DRAFT lib: Add missing pipe prototype. * include/unistd.h (pipe: New prototype. --- include/unistd.h | 1 + lib/stdio/pclose.c | 2 ++ lib/stdio/popen.c | 7 +++---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/unistd.h b/include/unistd.h index da566fbb..20a20fcb 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -82,6 +82,7 @@ int getpgid (pid_t pid); int isatty (int fd); int link (char const *old_name, char const *new_name); off_t lseek (int fd, off_t offset, int whence); +int pipe (int filedes[2]); ssize_t read (int fd, void *buffer, size_t size); ssize_t readlink (char const *file_name, char *buffer, size_t size); #if __SBRK_CHAR_PTRDIFF diff --git a/lib/stdio/pclose.c b/lib/stdio/pclose.c index 20d91206..72dd6755 100644 --- a/lib/stdio/pclose.c +++ b/lib/stdio/pclose.c @@ -26,6 +26,8 @@ #include #include +extern int *__ungetc_buf; + int pclose (FILE *stream) { diff --git a/lib/stdio/popen.c b/lib/stdio/popen.c index 71b43204..3afe4e05 100644 --- a/lib/stdio/popen.c +++ b/lib/stdio/popen.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -34,8 +35,6 @@ #define SHELL_COMMAND_NAME "sh" #endif -extern int *__ungetc_buf; - FILE * popen (char const *command, char const *mode) { @@ -61,7 +60,7 @@ popen (char const *command, char const *mode) // child int dup = (*mode == 'w' ? dup2 (pipedes[STDIN], STDIN) - : dup2 (pipedes[STDOUT], STDOUT)) + : dup2 (pipedes[STDOUT], STDOUT)); if (dup < 0) _exit (127); @@ -109,6 +108,6 @@ popen (char const *command, char const *mode) // XXX misuse ungetc buffer for PID // XXX TODO: make proper FILE struct __ungetc_init (); - __ungetc_set (filedes, pidchild); + __ungetc_set (filedes, pid); return stream; }