summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxhe <xw897002528@gmail.com>2017-05-21 22:00:32 +0800
committerxhe <xw897002528@gmail.com>2017-05-27 22:54:53 +0800
commit6164461b7ee850da5b577b96b120e2a4b1b05a09 (patch)
tree703adbbce81eb8b2f95449af41aad901551275cb
parentd98cd87f5f476e9a26946194c2f5c86ede7180b3 (diff)
downloadgettext-tiny-6164461b7ee850da5b577b96b120e2a4b1b05a09.tar.gz
fix bug of reading from stdin:
found when compiling dnsmasq we can't fseek in stdin, we can only read it for one time so now i write them to a temporary file first instead
-rw-r--r--src/msgfmt.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/msgfmt.c b/src/msgfmt.c
index 362e403..df5ed39 100644
--- a/src/msgfmt.c
+++ b/src/msgfmt.c
@@ -475,7 +475,21 @@ int process(FILE *in, FILE *out) {
void set_file(int out, char* fn, FILE** dest) {
if(streq(fn, "-")) {
- *dest = out ? stdout : stdin;
+ if(out) {
+ *dest = stdout;
+ } else {
+ char b[4096];
+ size_t n=0;
+ FILE* tmpf = tmpfile();
+ if(!tmpf)
+ perror("tmpfile");
+
+ while((n=fread(b, sizeof(*b), sizeof(b), stdin)) > 0)
+ fwrite(b, sizeof(*b), n, tmpf);
+
+ fseek(tmpf, 0, SEEK_SET);
+ *dest = tmpf;
+ }
} else {
*dest = fopen(fn, out ? "w" : "r");
}
@@ -553,9 +567,15 @@ int main(int argc, char**argv) {
// no support for -d at this time
fprintf(stderr, "EINVAL\n");
exit(1);
- } else if (streq(A+1, "h")) syntax();
+ } else if (streq(A+1, "h")) {
+ syntax();
+ } else if (expect_in_fn) {
+ set_file(0, A, &in);
+ expect_in_fn = 0;
+ }
} else if (expect_in_fn) {
set_file(0, A, &in);
+ expect_in_fn = 0;
}
}
if(in == NULL || out == NULL) {