diff options
author | dpatel <dpatel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-02-19 19:48:02 +0000 |
---|---|---|
committer | dpatel <dpatel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-02-19 19:48:02 +0000 |
commit | f86986bc4138190a73652471c3e7af5d2a62a0d3 (patch) | |
tree | 374c60752b401e773bee9a1c4325104556d62c52 /libcpp/charset.c | |
parent | 25bd9e4227796ca0c4d3ccd7bbfbd471f1b12075 (diff) | |
download | gcc-f86986bc4138190a73652471c3e7af5d2a62a0d3.tar.gz |
* 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
Diffstat (limited to 'libcpp/charset.c')
-rw-r--r-- | libcpp/charset.c | 10 |
1 files changed, 9 insertions, 1 deletions
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; } |