From f86986bc4138190a73652471c3e7af5d2a62a0d3 Mon Sep 17 00:00:00 2001 From: dpatel Date: Sat, 19 Feb 2005 19:48:02 +0000 Subject: [PATCH] * charset.c (_cpp_convert_input): Check '\r' before inserting '\n' at the end. * gcc.dg/cpp/mac-eol-at-eof.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@95289 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/cpp/mac-eol-at-eof.c | 1 + libcpp/ChangeLog | 5 +++++ libcpp/charset.c | 10 +++++++++- 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/cpp/mac-eol-at-eof.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6d09ca0..8e083a9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2005-02-19 Devang Patel + + * gcc.dg/cpp/mac-eol-at-eof.c: New test. + 2005-02-19 Steven G. Kargl * gfortran.dg/achar_1.f90: New test. diff --git a/gcc/testsuite/gcc.dg/cpp/mac-eol-at-eof.c b/gcc/testsuite/gcc.dg/cpp/mac-eol-at-eof.c new file mode 100644 index 0000000..6b0a279 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/mac-eol-at-eof.c @@ -0,0 +1 @@ +/* Test no newline at eof warning when Mac line ending is used*/ /* { dg-do compile } */ int main() { return 0; } \ No newline at end of file diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 5c58eb7..0764fc8 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,8 @@ +2005-02-19 Devang Patel + + * charset.c (_cpp_convert_input): Check '\r' before inserting + '\n' at the end. + 2005-02-15 Eric Christopher PR preprocessor/19077 diff --git a/libcpp/charset.c b/libcpp/charset.c index 7a88a70..37859c5 100644 --- a/libcpp/charset.c +++ b/libcpp/charset.c @@ -1405,7 +1405,15 @@ _cpp_convert_input (cpp_reader *pfile, const char *input_charset, if (to.len + 4096 < to.asize || to.len >= to.asize) to.text = xrealloc (to.text, to.len + 1); - to.text[to.len] = '\n'; + /* If the file is using old-school Mac line endings (\r only), + terminate with another \r, not an \n, so that we do not mistake + the \r\n sequence for a single DOS line ending and erroneously + issue the "No newline at end of file" diagnostic. */ + if (to.text[to.len - 1] == '\r') + to.text[to.len] = '\r'; + else + to.text[to.len] = '\n'; + *st_size = to.len; return to.text; } -- 2.7.4