From: "Mark E." To: djgpp-workers AT delorie DOT com Date: Thu, 22 Mar 2001 00:07:55 -0500 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: pipe() emulation Message-ID: <3AB9425B.11812.36ACFC@localhost> X-mailer: Pegasus Mail for Win32 (v3.12c) Reply-To: djgpp-workers AT delorie DOT com Hi all, This patch implements pipe() using a temporary file. It's based on the pipe.c replacement in bash 2.04 and is updated to use O_TEMPORARY. Comments and objections? Index: pipe.c =================================================================== RCS file: /cvs/djgpp/djgpp/src/libc/posix/unistd/pipe.c,v retrieving revision 1.1 diff -c -p -r1.1 pipe.c *** pipe.c 1995/04/01 23:49:02 1.1 --- pipe.c 2001/03/22 05:01:59 *************** *** 1,10 **** /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include ! #include int pipe(int _fildes[2]) { ! errno = EACCES; ! return -1; } --- 1,53 ---- + /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include ! #include ! #include ! #include ! #include + /* Emulate a pipe using a temporary file. */ int pipe(int _fildes[2]) { ! int ifd, ofd; ! char temp_name[FILENAME_MAX + 1]; ! char *tname; ! ! tname = tmpnam(temp_name); ! if (tname == NULL) ! return -1; ! ! ofd = open(tname, O_WRONLY | O_CREAT | O_TRUNC | O_TEMPORARY, S_IWUSR); ! if (ofd < 0) ! return -1; ! ! /* Move the handle up so it doesn't count against the 20 handle ! inherit limit. */ ! if (ofd < 20) ! { ! int high_fd; ! ! high_fd = fcntl(ofd, F_DUPFD, 20); ! close(ofd); ! ofd = high_fd; ! } ! ! ifd = open(tname, O_RDONLY | O_TEMPORARY, S_IWUSR); ! if (ifd < 0) ! return -1; ! ! /* Move this handle up too. */ ! if (ifd < 20) ! { ! int high_fd; ! high_fd = fcntl (ifd, F_DUPFD, 20); ! close(ifd); ! ifd = high_fd; ! } ! ! _fildes[0] = ifd; ! _fildes[1] = ofd; ! ! return 0; }