From 363eac9564bebc4b0714f8920845adbbc9ac31be Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 9 Apr 2009 04:02:28 -0400 Subject: [PATCH] Don't report false error when writing a zero-byte file. Fixes unit tests: preprocessor/output/empty-file preprocessor/output/just-a-comment --- utils/mojoshader-compiler.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/utils/mojoshader-compiler.c b/utils/mojoshader-compiler.c index 3b9abace..0df9c9bf 100644 --- a/utils/mojoshader-compiler.c +++ b/utils/mojoshader-compiler.c @@ -136,7 +136,8 @@ static int preprocess(const char *fname, const char *buf, int len, { if (pd->output != NULL) { - if (fwrite(pd->output, pd->output_len, 1, io) != 1) + const int len = pd->output_len; + if ((len) && (fwrite(pd->output, len, 1, io) != 1)) printf(" ... fwrite('%s') failed.\n", outfile); else if ((outfile != NULL) && (fclose(io) == EOF)) printf(" ... fclose('%s') failed.\n", outfile); @@ -177,7 +178,8 @@ static int assemble(const char *fname, const char *buf, int len, { if (pd->output != NULL) { - if (fwrite(pd->output, pd->output_len, 1, io) != 1) + const int len = pd->output_len; + if ((len) && (fwrite(pd->output, len, 1, io) != 1)) printf(" ... fwrite('%s') failed.\n", outfile); else if ((outfile != NULL) && (fclose(io) == EOF)) printf(" ... fclose('%s') failed.\n", outfile);