From 8b24c7008aadf62bd6803778ab04fdd065d573d8 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 19 Nov 2016 01:06:01 -0800 Subject: [PATCH 01/10] grep: avoid unnecessary isatty calls This fixes an inefficiency that was mistakenly introduced a while back, when the macro SET_BINARY became defined on all platforms. * src/grep.c (grepdesc, main): Do not unecessarily call isatty on POSIXish platforms. --- src/grep.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/grep.c b/src/grep.c index 1163eae..201b1d9 100644 --- a/src/grep.c +++ b/src/grep.c @@ -1834,12 +1834,10 @@ grepdesc (int desc, bool command_line) goto closeout; } -#if defined SET_BINARY /* Set input to binary mode. Pipes are simulated with files on DOS, so this includes the case of "foo | grep bar". */ - if (!isatty (desc)) - SET_BINARY (desc); -#endif + if (O_BINARY && !isatty (desc)) + set_binary_mode (desc, O_BINARY); count = grep (desc, &st); if (count_matches) @@ -2801,12 +2799,10 @@ main (int argc, char **argv) if ((argc - optind > 1 && !no_filenames) || with_filenames) out_file = 1; -#ifdef SET_BINARY /* Output is set to binary mode because we shouldn't convert NL to CR-LF pairs, especially when grepping binary files. */ - if (!isatty (STDOUT_FILENO)) - SET_BINARY (STDOUT_FILENO); -#endif + if (O_BINARY && !isatty (STDOUT_FILENO)) + set_binary_mode (STDOUT_FILENO, O_BINARY); if (max_count == 0) return EXIT_FAILURE; -- 2.7.4