From 04c90eea0779dd173baa01b96aed683fec326207 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Sat, 19 Feb 2005 11:48:02 -0800 Subject: 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 --- libcpp/charset.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'libcpp/charset.c') diff --git a/libcpp/charset.c b/libcpp/charset.c index 7a88a708e6c..37859c52a31 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; } -- cgit v1.2.1