- /* Main body */
- if ((argc - optind) != 2) { /* There must two argument */
- printf("Wrong number of arguments %d\n", argc - optind);
- usage();
- }
- /* open pipe, input and output file */
- in_fd = open(argv[optind], O_RDONLY);
- if (in_fd < 0) {
- printf("Input error %s on %s\n", strerror(errno), argv[optind]);
- exit(EXIT_FAILURE);
- }
- out_fd = open(argv[optind+1], O_CREAT|O_RDWR|O_TRUNC, 0644);
- if (out_fd < 0) {
- printf("Cannot open %s, error %s\n", argv[optind+1], strerror(errno));
- exit(EXIT_FAILURE);
- }
- if (pipe(pipefd) == -1) {
- perror("Cannot create buffer pipe");
- exit(EXIT_FAILURE);
- }