gunzip: support decompressing from stdin
This commit is contained in:
parent
c43fc42b8a
commit
75ece46da9
|
@ -13,6 +13,9 @@
|
||||||
|
|
||||||
#include <toaru/inflate.h>
|
#include <toaru/inflate.h>
|
||||||
|
|
||||||
|
static int to_stdout = 0;
|
||||||
|
static int keep = 0;
|
||||||
|
|
||||||
static uint8_t _get(struct inflate_context * ctx) {
|
static uint8_t _get(struct inflate_context * ctx) {
|
||||||
return fgetc(ctx->input_priv);
|
return fgetc(ctx->input_priv);
|
||||||
}
|
}
|
||||||
|
@ -34,11 +37,9 @@ static int usage(int argc, char * argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
int to_stdout = 0;
|
|
||||||
int keep = 0;
|
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt(argc, argv, "ck")) != -1) {
|
while ((opt = getopt(argc, argv, "?ck")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'c':
|
case 'c':
|
||||||
to_stdout = 1;
|
to_stdout = 1;
|
||||||
|
@ -47,18 +48,21 @@ int main(int argc, char * argv[]) {
|
||||||
case 'k':
|
case 'k':
|
||||||
keep = 1;
|
keep = 1;
|
||||||
break;
|
break;
|
||||||
|
case '?':
|
||||||
|
return usage(argc, argv);
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "%s: unrecognized option '%c'\n", argv[0], opt);
|
fprintf(stderr, "%s: unrecognized option '%c'\n", argv[0], opt);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optind >= argc) {
|
FILE * f;
|
||||||
return usage(argc, argv);
|
if (optind >= argc || !strcmp(argv[optind],"-")) {
|
||||||
|
f = stdin;
|
||||||
|
} else {
|
||||||
|
f =fopen(argv[optind],"r");
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE * f = fopen(argv[optind],"r");
|
|
||||||
|
|
||||||
if (!f) {
|
if (!f) {
|
||||||
fprintf(stderr, "%s: %s: %s\n", argv[0], argv[optind], strerror(errno));
|
fprintf(stderr, "%s: %s: %s\n", argv[0], argv[optind], strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in New Issue