Header cleanup on two more networking files (move libbb.h to the top and
[oweals/busybox.git] / coreutils / tee.c
index bb28966639c833d2f1b0655d6b195947a148a039..1160fc9dd51a39a8ea2390e3afd91160954b32a6 100644 (file)
@@ -38,8 +38,8 @@ int tee_main(int argc, char **argv)
        int flags;
        int retval = EXIT_SUCCESS;
 #ifdef CONFIG_FEATURE_TEE_USE_BLOCK_IO
-       size_t c;
-       RESERVE_CONFIG_BUFFER(buf, BUFSIZ);
+       ssize_t c;
+# define buf bb_common_bufsiz1
 #else
        int c;
 #endif
@@ -78,15 +78,15 @@ int tee_main(int argc, char **argv)
        *p = NULL;                              /* Store the sentinal value. */
 
 #ifdef CONFIG_FEATURE_TEE_USE_BLOCK_IO
-       while ((c = fread(buf, 1, BUFSIZ, stdin)) != 0) {
+       while ((c = safe_read(STDIN_FILENO, buf, BUFSIZ)) > 0) {
                for (p=files ; *p ; p++) {
                        fwrite(buf, 1, c, *p);
                }
        }
 
-#ifdef CONFIG_FEATURE_CLEAN_UP
-       RELEASE_CONFIG_BUFFER(buf);
-#endif
+       if (c < 0) {                    /* Make sure read errors are signaled. */
+               retval = EXIT_FAILURE;
+       }
 
 #else
        setvbuf(stdout, NULL, _IONBF, 0);