]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
charset.c (_cpp_convert_input): Check '\r' before inserting '\n' at the end.
authorDevang Patel <dpatel@apple.com>
Sat, 19 Feb 2005 19:48:02 +0000 (11:48 -0800)
committerDevang Patel <dpatel@gcc.gnu.org>
Sat, 19 Feb 2005 19:48:02 +0000 (11:48 -0800)
      * 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

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/mac-eol-at-eof.c [new file with mode: 0644]
libcpp/ChangeLog
libcpp/charset.c

index 6d09ca0b334a93646635a5f5825964140666d265..8e083a9ac85b6c4e8da451ff9fe12cac6497dc1a 100644 (file)
@@ -1,3 +1,7 @@
+2005-02-19  Devang Patel  <dpatel@apple.com>
+
+       * gcc.dg/cpp/mac-eol-at-eof.c: New test.
+       
 2005-02-19  Steven G. Kargl  <kargls@comcast.net>
 
        * 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 (file)
index 0000000..6b0a279
--- /dev/null
@@ -0,0 +1 @@
+/* Test no newline at eof warning when Mac line ending is used*/\r/* { dg-do compile } */\rint main() { return 0; } \r
\ No newline at end of file
index 5c58eb7ceb803ddbb56bdf281a541155f95f065f..0764fc8e4b306843ad3e147a4a74ca09ba855167 100644 (file)
@@ -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
index 7a88a708e6c43ea4e7e348c1e2597fe194bb7656..37859c52a319a632f8104518d0c8e0b927b2cdd1 100644 (file)
@@ -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;
 }