.\" SUCH DAMAGE.
.\"
.\" @(#)popen.3 8.2 (Berkeley) 5/3/95
-.\" $FreeBSD: src/lib/libc/gen/popen.3,v 1.15 2003/01/03 05:21:59 tjr Exp $
+.\" $FreeBSD: src/lib/libc/gen/popen.3,v 1.16 2003/06/08 10:01:51 charnier Exp $
.\"
.Dd May 3, 1995
.Dt POPEN 3
.Os
.Sh NAME
-.Nm popen ,
-.Nm pclose
+.Nm pclose ,
+.Nm popen
.Nd process
.Tn I/O
.Sh LIBRARY
.Sh SYNOPSIS
.In stdio.h
.Ft FILE *
-.Fn popen "const char *command" "const char *type"
+.Fo popen
+.Fa "const char *command"
+.Fa "const char *mode"
+.Fc
.Ft int
-.Fn pclose "FILE *stream"
+.Fo pclose
+.Fa "FILE *stream"
+.Fc
.Sh DESCRIPTION
The
.Fn popen
function
.Dq opens
-a process by creating a bidirectional pipe
-forking,
+a process by creating a bidirectional pipe, forking,
and invoking the shell.
Any streams opened by previous
.Fn popen
Historically,
.Fn popen
was implemented with a unidirectional pipe;
-hence many implementations of
+hence, many implementations of
.Fn popen
only allow the
-.Fa type
+.Fa mode
argument to specify reading or writing, not both.
-Since
+Because
.Fn popen
is now implemented using a bidirectional pipe, the
-.Fa type
+.Fa mode
argument may request a bidirectional data flow.
The
-.Fa type
+.Fa mode
argument is a pointer to a null-terminated string
which must be
.Ql r
argument is a pointer to a null-terminated string
containing a shell command line.
This command is passed to
-.Pa /bin/sh
+.Pa /bin/sh ,
using the
.Fl c
flag; interpretation, if any, is performed by the shell.
.Fn popen
is a normal standard
.Tn I/O
-stream in all respects
+stream in all respects,
save that it must be closed with
.Fn pclose
rather than
.Pp
Note that output
.Fn popen
-streams are fully buffered by default.
+streams are fully buffered, by default.
.Pp
The
.Fn pclose
-function waits for the associated process to terminate
-and returns the exit status of the command
+function waits for the associated process to terminate;
+it returns the exit status of the command,
as returned by
-.Fn wait4 .
+.Xr wait4 2 .
.Sh RETURN VALUES
The
.Fn popen
already
.Dq pclosed ,
or if
-.Xr wait4
+.Xr wait4 2
returns an error.
.Sh ERRORS
The