From 4354c9fc7af4f5de714420c8aad674744f61980d Mon Sep 17 00:00:00 2001 From: Nils Homer Date: Wed, 28 Oct 2015 13:51:11 -0400 Subject: [PATCH] properly read in from stdin, either by having no arguments or passing in "-" --- pbgzip.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pbgzip.c b/pbgzip.c index 1bfccd9..68afb3e 100644 --- a/pbgzip.c +++ b/pbgzip.c @@ -151,7 +151,11 @@ main(int argc, char *argv[]) } } - if ((f_src = open(argv[optind], O_RDONLY)) < 0) { + // read from stdin if no more arguments, or a "-", are/is supplied. + if (optind == argc || 0 == strcmp(argv[optind], "-")) { + f_src = fileno(stdin); + } + else if ((f_src = open(argv[optind], O_RDONLY)) < 0) { fprintf(stderr, "[pbgzip] %s: %s\n", strerror(errno), argv[optind]); return 1; }