summaryrefslogtreecommitdiffstats
path: root/man2/pipe.2
diff options
context:
space:
mode:
Diffstat (limited to 'man2/pipe.2')
-rw-r--r--man2/pipe.216
1 files changed, 8 insertions, 8 deletions
diff --git a/man2/pipe.2 b/man2/pipe.2
index adf6d73bf..3634a8c27 100644
--- a/man2/pipe.2
+++ b/man2/pipe.2
@@ -248,40 +248,40 @@ and echoes it on standard output.
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
int pipefd[2];
char buf;
pid_t cpid;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s <string>\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
if (pipe(pipefd) == \-1) {
perror("pipe");
exit(EXIT_FAILURE);
}
-
+\&
cpid = fork();
if (cpid == \-1) {
perror("fork");
exit(EXIT_FAILURE);
}
-
+\&
if (cpid == 0) { /* Child reads from pipe */
close(pipefd[1]); /* Close unused write end */
-
+\&
while (read(pipefd[0], &buf, 1) > 0)
write(STDOUT_FILENO, &buf, 1);
-
+\&
write(STDOUT_FILENO, "\en", 1);
close(pipefd[0]);
_exit(EXIT_SUCCESS);
-
+\&
} else { /* Parent writes argv[1] to pipe */
close(pipefd[0]); /* Close unused read end */
write(pipefd[1], argv[1], strlen(argv[1]));