aboutsummaryrefslogtreecommitdiff
path: root/gcc/cppmain.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cppmain.c')
-rw-r--r--gcc/cppmain.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/gcc/cppmain.c b/gcc/cppmain.c
index e7d82b5..0d891f8 100644
--- a/gcc/cppmain.c
+++ b/gcc/cppmain.c
@@ -46,6 +46,7 @@ main (argc, argv)
char *p;
int argi = 1; /* Next argument to handle. */
struct cpp_options *opts = &options;
+ enum cpp_token kind;
p = argv[0] + strlen (argv[0]);
while (p != argv[0] && p[-1] != '/') --p;
@@ -80,21 +81,30 @@ main (argc, argv)
else if (! freopen (opts->out_fname, "w", stdout))
cpp_pfatal_with_name (&parse_in, opts->out_fname);
- for (;;)
+ do
{
- enum cpp_token kind;
- if (! opts->no_output)
+ kind = cpp_get_token (&parse_in);
+ if (CPP_WRITTEN (&parse_in) >= BUFSIZ || kind == CPP_EOF)
{
- fwrite (parse_in.token_buffer, 1, CPP_WRITTEN (&parse_in), stdout);
+ if (! opts->no_output)
+ {
+ size_t rem, count = CPP_WRITTEN (&parse_in);
+
+ rem = fwrite (parse_in.token_buffer, 1, count, stdout);
+ if (rem < count)
+ /* Write error. */
+ cpp_pfatal_with_name (&parse_in, opts->out_fname);
+ }
+
+ CPP_SET_WRITTEN (&parse_in, 0);
}
- CPP_SET_WRITTEN (&parse_in, 0);
- kind = cpp_get_token (&parse_in);
- if (kind == CPP_EOF)
- break;
}
+ while (kind != CPP_EOF);
cpp_finish (&parse_in);
- fwrite (parse_in.token_buffer, 1, CPP_WRITTEN (&parse_in), stdout);
+ if (fwrite (parse_in.token_buffer, 1, CPP_WRITTEN (&parse_in), stdout)
+ < CPP_WRITTEN (&parse_in))
+ cpp_pfatal_with_name (&parse_in, opts->out_fname);
if (parse_in.errors)
exit (FATAL_EXIT_CODE);