Mail Archives: djgpp-workers/2001/03/22/00:10:41
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 <unistd.h>
! #include <errno.h>
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 <unistd.h>
! #include <stdlib.h>
! #include <fcntl.h>
! #include <stdio.h>
! #include <sys/stat.h>
+ /* 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;
}
- Raw text -