aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2005-02-19 11:48:02 -0800
committerDevang Patel <dpatel@gcc.gnu.org>2005-02-19 11:48:02 -0800
commit04c90eea0779dd173baa01b96aed683fec326207 (patch)
tree374c60752b401e773bee9a1c4325104556d62c52 /libcpp
parent332e7efe7fa434a998aa5634dca6d4f93810f65f (diff)
downloadgcc-04c90eea0779dd173baa01b96aed683fec326207.zip
gcc-04c90eea0779dd173baa01b96aed683fec326207.tar.gz
gcc-04c90eea0779dd173baa01b96aed683fec326207.tar.bz2
charset.c (_cpp_convert_input): Check '\r' before inserting '\n' at the end.
* charset.c (_cpp_convert_input): Check '\r' before inserting '\n' at the end. * gcc.dg/cpp/mac-eol-at-eof.c: New test. From-SVN: r95289
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog5
-rw-r--r--libcpp/charset.c10
2 files changed, 14 insertions, 1 deletions
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 <dpatel@apple.com>
+
+ * charset.c (_cpp_convert_input): Check '\r' before inserting
+ '\n' at the end.
+
2005-02-15 Eric Christopher <echristo@redhat.com>
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;
}