summaryrefslogtreecommitdiff
path: root/gcc/cppmain.c
diff options
context:
space:
mode:
authorZack Weinberg <zack@rabi.columbia.edu>1999-05-10 11:24:36 -0400
committerDave Brolley <brolley@gcc.gnu.org>1999-05-10 11:24:36 -0400
commit2c826217f4703c5d4f7b5739607743f693e92842 (patch)
tree82da63a000e57cc2f3aa9bf724d12d755a4e166f /gcc/cppmain.c
parent4338f578a7e549d521d9f8b80a8f0eaca39d1fee (diff)
downloadgcc-2c826217f4703c5d4f7b5739607743f693e92842.tar.gz
cppfiles.c (initialize_input_buffer): New function.
1999-05-10 18:21 -0400 Zack Weinberg <zack@rabi.columbia.edu> * cppfiles.c (initialize_input_buffer): New function. (finclude): Call it, if pfile->input_buffer is NULL. Accept any character device as an input file. (read_and_prescan): Use pfile->input_buffer and pfile->input_speccase. * cppinit.c (cpp_cleanup): Free pfile->input_buffer and pfile->input_speccase. * cpplib.h (cpp_reader): Add input_buffer, input_speccase, and input_buffer_len members. Use memcpy in CPP_PUTS_Q. * cppmain.c: Buffer output in the token_buffer; throttle number of calls to fwrite; check for errors from fwrite. From-SVN: r26869
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 e7d82b5429b..0d891f80980 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);