/* * tee: pipe fitting */ #include char append=0; main(argc, argv) char **argv; { char text[200]; FILE *tee; if (argc > 1 && strcmp(argv[1], "-a") == 0) { ++argv; --argc; append = 1; } if (argc < 2) { fprintf(stderr, "usage: tee [-a] file\n"); exit(99); } if (tee = fopen(argv[1], append ? "ab" : "wb")) { while (fgets(text, 200, stdin)) { fputs(text, stdout); fputs(text, tee); } close(tee); exit(0); } fprintf(stderr, "tee: can't open %s\n", argv[1]); exit(1); }