BSD 4_4_Lite2 release
[unix-history] / usr / src / lib / libc / gen / popen.3
index c2f95f9..9ca1bb3 100644 (file)
@@ -1,11 +1,37 @@
 .\" Copyright (c) 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
 .\"
 .\" Copyright (c) 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
 .\"
-.\" %sccs.include.redist.roff%
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"    This product includes software developed by the University of
+.\"    California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
 .\"
 .\"
-.\"     @(#)popen.3    8.1 (Berkeley) %G%
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
 .\"
 .\"
-.Dd 
+.\"     @(#)popen.3    8.2 (Berkeley) 5/3/95
+.\"
+.Dd May 3, 1995
 .Dt POPEN 3
 .Os
 .Sh NAME
 .Dt POPEN 3
 .Os
 .Sh NAME
@@ -24,13 +50,32 @@ The
 .Fn popen
 function
 .Dq opens
 .Fn popen
 function
 .Dq opens
-a process by creating a pipe,
+a process by creating an IPC connection,
 forking,
 and invoking the shell.
 forking,
 and invoking the shell.
-Since a pipe is by definition unidirectional, the
+Historically,
+.Nm popen
+was implemented with a unidirectional pipe;
+hence many implementations of
+.Nm popen
+only allow the
+.Fa type
+argument to specify reading or writing, not both.
+Since
+.Nm popen
+is now implemented using sockets, the
+.Fa type
+may request a bidirectional data flow.
+The
 .Fa type
 .Fa type
-argument may specify only reading or writing, not both;
-the resulting stream is correspondingly read-only or write-only.
+argument is a pointer to a null-terminated string
+which must be
+.Ql r
+for reading,
+.Ql w
+for writing, or
+.Ql r+
+for reading and writing.
 .Pp
 The
 .Fa command
 .Pp
 The
 .Fa command
@@ -41,15 +86,6 @@ This command is passed to
 using the
 .Fl c
 flag; interpretation, if any, is performed by the shell.
 using the
 .Fl c
 flag; interpretation, if any, is performed by the shell.
-The
-.Fa mode
-argument is a pointer to a null-terminated string
-which must be either
-.Ql r
-for reading
-or
-.Ql w
-for writing.
 .Pp
 The return value from
 .Fn popen
 .Pp
 The return value from
 .Fn popen
@@ -87,9 +123,10 @@ The
 function returns
 .Dv NULL
 if the
 function returns
 .Dv NULL
 if the
-.Xr fork 2
+.Xr fork 2 ,
+.Xr pipe 2 ,
 or
 or
-.Xr pipe 2
+.Xr socketpair 2
 calls fail,
 or if it cannot allocate memory.
 .Pp
 calls fail,
 or if it cannot allocate memory.
 .Pp
@@ -116,6 +153,7 @@ function does not reliably set
 .Xr fork 2 ,
 .Xr sh 1 ,
 .Xr pipe 2 ,
 .Xr fork 2 ,
 .Xr sh 1 ,
 .Xr pipe 2 ,
+.Xr socketpair 2 ,
 .Xr wait4 2 ,
 .Xr fflush 3 ,
 .Xr fclose 3 ,
 .Xr wait4 2 ,
 .Xr fflush 3 ,
 .Xr fclose 3 ,