1 /* pipe.cc: pipe for Cygwin.
3 Copyright 1996, 1998, 1999, 2000 Cygnus Solutions.
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
13 #include <sys/fcntl.h>
22 make_pipe (int fildes[2], unsigned int psize, int mode)
24 SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," make_pipe");
28 SECURITY_ATTRIBUTES *sa = (mode & O_NOINHERIT) ? &sec_none_nih : &sec_none;
30 if ((fdr = fdtab.find_unused_handle ()) < 0)
32 else if ((fdw = fdtab.find_unused_handle (fdr + 1)) < 0)
34 else if (!CreatePipe (&r, &w, sa, psize))
38 fhandler_base *fhr = fdtab.build_fhandler (fdr, FH_PIPER, "/dev/piper");
39 fhandler_base *fhw = fdtab.build_fhandler (fdw, FH_PIPEW, "/dev/pipew");
41 int binmode = mode & O_TEXT ? 0 : 1;
42 fhr->init (r, GENERIC_READ, binmode);
43 fhw->init (w, GENERIC_WRITE, binmode);
44 if (mode & O_NOINHERIT)
46 fhr->set_close_on_exec_flag (1);
47 fhw->set_close_on_exec_flag (1);
53 debug_printf ("0 = pipe (%p) (%d:%p, %d:%p)", fildes,
54 fdr, fhr->get_handle (), fdw, fhw->get_handle ());
56 ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," make_pipe");
60 syscall_printf ("-1 = pipe (%p)", fildes);
61 ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," make_pipe");
69 return make_pipe (filedes, 16384, (!binmode || binmode == O_BINARY) ? O_BINARY : O_TEXT);
73 _pipe (int filedes[2], unsigned int psize, int mode)
75 int res = make_pipe (filedes, psize, mode);
76 /* This type of pipe is not interruptible so set the appropriate flag. */
78 fdtab[filedes[0]]->set_r_no_interrupt (1);
86 SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," dup");
88 res = dup2 (fd, fdtab.find_unused_handle ());
90 ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," dup");
96 dup2 (int oldfd, int newfd)
98 return fdtab.dup2 (oldfd, newfd);