commit f55ee4ade3427a75bf6dae3b1e20abf6d8e18e0c
parent aa7f57eed805adb09e9c59c8ea841870e8206b81
Author: Carlos Maddela <e7appew@gmail.com>
Date:   Thu, 30 Mar 2017 04:41:15 +1100
Perform fstat on stdin and stdout only if required.
Diffstat:
| M | xsel.c |  |  | 24 | ++++++++++++++---------- | 
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/xsel.c b/xsel.c
@@ -2117,18 +2117,22 @@ main(int argc, char *argv[])
     exit (0);
   }
 
-  if (fstat (0, &in_statbuf) == -1) {
-    exit_err ("fstat error on stdin");
-  }
-  if (fstat (1, &out_statbuf) == -1) {
-    exit_err ("fstat error on stdout");
+  if (do_input || force_input) {
+    if (fstat (0, &in_statbuf) == -1) {
+      exit_err ("fstat error on stdin");
+    }
+    if (S_ISDIR(in_statbuf.st_mode)) {
+      exit_err ("-: Is a directory\n");
+    }
   }
 
-  if (S_ISDIR(in_statbuf.st_mode)) {
-    exit_err ("-: Is a directory\n");
-  }
-  if (S_ISDIR(out_statbuf.st_mode)) {
-    exit_err ("stdout: Is a directory\n");
+  if (do_output || force_output) {
+    if (fstat (1, &out_statbuf) == -1) {
+      exit_err ("fstat error on stdout");
+    }
+    if (S_ISDIR(out_statbuf.st_mode)) {
+      exit_err ("stdout: Is a directory\n");
+    }
   }
 
   timeout = timeout_ms * 1000;