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>
17 make_pipe (int fildes[2], unsigned int psize, int mode)
19 SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," make_pipe");
23 SECURITY_ATTRIBUTES *sa = (mode & O_NOINHERIT) ? &sec_none_nih : &sec_none;
25 if ((fdr = fdtab.find_unused_handle ()) < 0)
27 else if ((fdw = fdtab.find_unused_handle (fdr + 1)) < 0)
29 else if (!CreatePipe (&r, &w, sa, psize))
33 fhandler_base *fhr = fdtab.build_fhandler (fdr, FH_PIPER, "/dev/piper");
34 fhandler_base *fhw = fdtab.build_fhandler (fdw, FH_PIPEW, "/dev/pipew");
36 int binmode = mode & O_TEXT ? 0 : 1;
37 fhr->init (r, GENERIC_READ, binmode);
38 fhw->init (w, GENERIC_WRITE, binmode);
39 if (mode & O_NOINHERIT)
41 fhr->set_close_on_exec_flag (1);
42 fhw->set_close_on_exec_flag (1);
48 debug_printf ("0 = pipe (%p) (%d:%p, %d:%p)", fildes,
49 fdr, fhr->get_handle (), fdw, fhw->get_handle ());
51 ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," make_pipe");
55 syscall_printf ("-1 = pipe (%p)", fildes);
56 ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," make_pipe");
63 return make_pipe (filedes, 16384, (!__fmode || __fmode == O_BINARY) ? O_BINARY : O_TEXT);
67 _pipe (int filedes[2], unsigned int psize, int mode)
69 int res = make_pipe (filedes, psize, mode);
70 /* This type of pipe is not interruptible so set the appropriate flag. */
72 fdtab[filedes[0]]->set_r_no_interrupt (1);
80 SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," dup");
82 res = dup2 (fd, fdtab.find_unused_handle ());
84 ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," dup");
90 dup2 (int oldfd, int newfd)
92 return fdtab.dup2 (oldfd, newfd);