proper_name ("Richard M. Stallman"), \
proper_name ("David MacKenzie")
-static bool tee_files (int nfiles, const char **files);
+static bool tee_files (int nfiles, char **files);
/* If true, append to output files rather than truncating them. */
static bool append;
/* Do *not* warn if tee is given no file arguments.
POSIX requires that it work when given no arguments. */
- ok = tee_files (argc - optind, (const char **) &argv[optind]);
+ ok = tee_files (argc - optind, &argv[optind]);
if (close (STDIN_FILENO) != 0)
error (EXIT_FAILURE, errno, _("standard input"));
}
/* Copy the standard input into each of the NFILES files in FILES
- and into the standard output.
+ and into the standard output. As a side effect, modify FILES[-1].
Return true if successful. */
static bool
-tee_files (int nfiles, const char **files)
+tee_files (int nfiles, char **files)
{
size_t n_outputs = 0;
FILE **descriptors;
? (append ? "ab" : "wb")
: (append ? "a" : "w"));
- descriptors = xnmalloc (nfiles + 1, sizeof *descriptors);
-
- /* Move all the names 'up' one in the argv array to make room for
- the entry for standard output. This writes into argv[argc]. */
- for (i = nfiles; i >= 1; i--)
- files[i] = files[i - 1];
-
if (O_BINARY && ! isatty (STDIN_FILENO))
xfreopen (NULL, "rb", stdin);
if (O_BINARY && ! isatty (STDOUT_FILENO))
fadvise (stdin, FADVISE_SEQUENTIAL);
- /* In the array of NFILES + 1 descriptors, make
- the first one correspond to standard output. */
+ /* Set up FILES[0 .. NFILES] and DESCRIPTORS[0 .. NFILES].
+ In both arrays, entry 0 corresponds to standard output. */
+
+ descriptors = xnmalloc (nfiles + 1, sizeof *descriptors);
+ files--;
descriptors[0] = stdout;
- files[0] = _("standard output");
+ files[0] = bad_cast (_("standard output"));
setvbuf (stdout, NULL, _IONBF, 0);
n_outputs++;