#include #include #include #include #include #include #define BUFFER_SIZE (16 * 1024) int main(int argc, char *argv[]) { char buffer[BUFFER_SIZE]; int read_size; int in_file; int out_file; int ch; //EOF if(argc != 3){ fprintf(stderr, "Error: Wrong number of arguments\n"); fprintf(stderr, "Usage is copy \n"); exit(8); } in_file = open(argv[1], O_RDONLY); if(in_file < 0){ fprintf(stderr, "Error: Unable to open %s\n",argv[1]); exit(8); } out_file = open(argv[2], O_WRONLY|O_TRUNC|O_CREAT, 0666); if(out_file < 0){ fprintf(stderr, "Error: Unable to open %s\n",argv[2]); exit(8); } while(1){ read_size = read(in_file, buffer, sizeof(buffer)); if(read_size == 0) break; if(read_size < 0){ fprintf(stderr, "Error: Read error\n"); exit(8); } write(out_file, buffer, (unsigned int) read_size); } while(ch != EOF){ ch = fgetc(out_file); if(ch == '\t') { fputs(" ", out_file); } } close(in_file); close(out_file); return 0; }