Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/coreutils/tee.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/coreutils/tee.c
r1765 r2725 5 5 * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> 6 6 * 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 8 */ 9 9 … … 12 12 13 13 #include "libbb.h" 14 #include <signal.h>15 14 16 int tee_main(int argc, char **argv) ;15 int tee_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 17 16 int tee_main(int argc, char **argv) 18 17 { … … 23 22 char **np; 24 23 char retval; 24 //TODO: make unconditional 25 25 #if ENABLE_FEATURE_TEE_USE_BLOCK_IO 26 26 ssize_t c; … … 36 36 37 37 if (retval & 1) { 38 signal(SIGINT, SIG_IGN); /* TODO - switch to sigaction. */38 signal(SIGINT, SIG_IGN); /* TODO - switch to sigaction. (why?) */ 39 39 } 40 40 retval = EXIT_SUCCESS; 41 41 /* gnu tee ignores SIGPIPE in case one of the output files is a pipe 42 42 * that doesn't consume all its input. Good idea... */ 43 signal(SIGPIPE, SIG_IGN); /* TODO - switch to sigaction. */43 signal(SIGPIPE, SIG_IGN); 44 44 45 /* Allocate an array of FILE *'s, with one extra for a sentin al. */45 /* Allocate an array of FILE *'s, with one extra for a sentinel. */ 46 46 fp = files = xzalloc(sizeof(FILE *) * (argc + 2)); 47 47 np = names = argv - 1; … … 50 50 goto GOT_NEW_FILE; 51 51 do { 52 *fp = fopen_or_warn(*argv, mode); 53 if (*fp == NULL) { 54 retval = EXIT_FAILURE; 55 continue; 52 *fp = stdout; 53 if (NOT_LONE_DASH(*argv)) { 54 *fp = fopen_or_warn(*argv, mode); 55 if (*fp == NULL) { 56 retval = EXIT_FAILURE; 57 argv++; 58 continue; 59 } 56 60 } 57 61 *np = *argv++; 58 62 GOT_NEW_FILE: 59 setbuf(*fp++, NULL); /* tee must not buffer output. */ 63 setbuf(*fp, NULL); /* tee must not buffer output. */ 64 fp++; 60 65 np++; 61 66 } while (*argv); … … 63 68 64 69 #if ENABLE_FEATURE_TEE_USE_BLOCK_IO 65 while ((c = safe_read(STDIN_FILENO, buf, BUFSIZ)) > 0) {70 while ((c = safe_read(STDIN_FILENO, buf, sizeof(buf))) > 0) { 66 71 fp = files; 67 72 do 68 fwrite(buf, 1, c, *fp ++);69 while (* fp);73 fwrite(buf, 1, c, *fp); 74 while (*++fp); 70 75 } 71 76 if (c < 0) { /* Make sure read errors are signaled. */ … … 77 82 fp = files; 78 83 do 79 putc(c, *fp ++);80 while (* fp);84 putc(c, *fp); 85 while (*++fp); 81 86 } 82 87 #endif
Note:
See TracChangeset
for help on using the changeset viewer.