pipe_cat.c
00001 #include <sys/types.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <unistd.h>
00005
00006 int main()
00007 {
00008 char c;
00009 int descfich[2];
00010 if (pipe(descfich)) return EXIT_FAILURE;
00011
00012 switch (fork()) {
00013 case -1:
00014 return EXIT_FAILURE;
00015 case 0:
00016 close(descfich[1]);
00017 while(read(descfich[0], &c, 1) == 1) {
00018 putchar(c);
00019 }
00020 return 0;
00021 default:
00022 close(descfich[0]);
00023 while (read(STDIN_FILENO, &c, 1) == 1) {
00024 write(descfich[1], &c, 1);
00025 }
00026 return 0;
00027 }
00028 }