diff options
author | Guillaume Cottenceau <gc@mandriva.com> | 2001-05-14 13:47:49 +0000 |
---|---|---|
committer | Guillaume Cottenceau <gc@mandriva.com> | 2001-05-14 13:47:49 +0000 |
commit | f15aa3a552022743398a652165d76bf912c715e5 (patch) | |
tree | b58f8b4c47fc571fbb498d83a4bd4fca226ac6c4 /mdk-stage1/dietlibc/libugly/popen.c | |
parent | 189b01c358a1181ddc951adba97a0258d5fc2cf1 (diff) | |
download | drakx-f15aa3a552022743398a652165d76bf912c715e5.tar drakx-f15aa3a552022743398a652165d76bf912c715e5.tar.gz drakx-f15aa3a552022743398a652165d76bf912c715e5.tar.bz2 drakx-f15aa3a552022743398a652165d76bf912c715e5.tar.xz drakx-f15aa3a552022743398a652165d76bf912c715e5.zip |
Initial revision
Diffstat (limited to 'mdk-stage1/dietlibc/libugly/popen.c')
-rw-r--r-- | mdk-stage1/dietlibc/libugly/popen.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/mdk-stage1/dietlibc/libugly/popen.c b/mdk-stage1/dietlibc/libugly/popen.c new file mode 100644 index 000000000..e0e441495 --- /dev/null +++ b/mdk-stage1/dietlibc/libugly/popen.c @@ -0,0 +1,32 @@ +#include "dietstdio.h" +#include <unistd.h> + +extern char **environ; + +FILE *popen(const char *command, const char *type) { + int pfd[2]; + int fd0; + pid_t pid; + if (pipe(pfd)<0) return 0; + fd0=(*type=='r'); + if ((pid=vfork())<0) { + close(pfd[0]); + close(pfd[1]); + return 0; + } + if (!pid) { /* child */ + char *argv[]={"sh","-c",0,0}; + close(pfd[!fd0]); close(fd0); + dup2(pfd[fd0],fd0); close(pfd[fd0]); + argv[2]=(char*)command; + execve("/bin/sh",argv,environ); + _exit(255); + } + close(pfd[fd0]); + { + register FILE* f; + if ((f=fdopen(pfd[!fd0],type))) + f->popen_kludge=pid; + return f; + } +} |