From 7d629481d48982c3ab7882afbdea8f38cfe96524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Tue, 17 Feb 2015 23:50:17 +0000 Subject: [PATCH] tee: treat '-' as a regular file with $POSIXLY_CORRECT * src/tee.c (usage): Adjust according to getenv("POSIXLY_CORRECT"). (main): Likewise. --- src/tee.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/tee.c b/src/tee.c index 4f185d6..b9390b9 100644 --- a/src/tee.c +++ b/src/tee.c @@ -44,6 +44,9 @@ static bool append; /* If true, ignore interrupts. */ static bool ignore_interrupts; +/* Whether '-' means stdout. */ +static bool posixly_correct; + enum write_error { write_error_sigpipe, /* traditional behavior, sigpipe enabled. */ @@ -95,7 +98,8 @@ Copy standard input to each FILE, and also to standard output.\n\ "), stdout); fputs (HELP_OPTION_DESCRIPTION, stdout); fputs (VERSION_OPTION_DESCRIPTION, stdout); - fputs (_("\ + if (! posixly_correct) + fputs (_("\ \n\ If a FILE is -, copy again to standard output.\n\ "), stdout); @@ -130,6 +134,8 @@ main (int argc, char **argv) atexit (close_stdout); + posixly_correct = !!getenv ("POSIXLY_CORRECT"); + append = false; ignore_interrupts = false; @@ -219,7 +225,7 @@ tee_files (int nfiles, const char **files) for (i = 1; i <= nfiles; i++) { - descriptors[i] = (STREQ (files[i], "-") + descriptors[i] = (! posixly_correct && STREQ (files[i], "-") ? stdout : fopen (files[i], mode_string)); if (descriptors[i] == NULL) -- 2.1.0