commit f3eb9c0d479fd45afc724c0cf3f5fcafd9162973
parent ee7b48111be2e2117b201962e9d1c0e1f9804ed4
Author: Conrad Parker <conrad@metadecks.org>
Date: Thu, 24 Aug 2017 09:56:44 +0800
Merge pull request #22 from e7appew/fstat-iff-needed
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
@@ -2128,18 +2128,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;