Don't report false error when writing a zero-byte file.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 09 Apr 2009 04:02:28 -0400
changeset 747 0d1dbadcb387
parent 746 6b368eeaa3fc
child 748 818ae6582f24
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
--- a/utils/mojoshader-compiler.c	Thu Apr 09 03:50:06 2009 -0400
+++ b/utils/mojoshader-compiler.c	Thu Apr 09 04:02:28 2009 -0400
@@ -136,7 +136,8 @@
     {
         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 @@
     {
         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);