Bug 4555 – Double newlines with std.file.readText

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-08-01T14:10:49Z
Last change time
2017-09-05T13:39:31Z
Keywords
bootcamp, trivial
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-08-01T14:10:49Z
This is a D2 program: import std.file: readText; import std.stdio: write; void main() { string s = readText("test.d"); write(s); } With DMD 2.047 on a 32 bit Windows Vista Home this D2 program prints all newlines doubled (assuming the program is named "test.d"): import std.file: readText; import std.stdio: write; void main() { string s = readText("test.d"); write(s); } Saving the same source code with in UNIX style the doubling of newlines doesn't happen. One or two testers have not found this problem on Windows XP. This program: import std.file: readText; import std.stdio: write; void main() { string s = readText("bug15.d"); foreach (c; s[0 .. 35]) write(cast(int)c, " "); } Prints: 105 109 112 111 114 116 32 115 116 100 46 102 105 108 101 58 32 114 101 97 100 84 101 120 116 59 13 10 105 109 112 111 114 116 32 Note the normal sequence of the newline of the first line plus the "i" char at the start of the second line: 13 10 105
Comment #1 by bus_dbugzilla — 2013-03-21T08:03:08Z
The 'write' function converts \n to \r\n on windows (And therefore also converts \r\n to \r\r\n). Is it possible this problem is *just* write and not readText at all? Try converting all of the 'write' into 'stdout.rawWrite'. Also, since windows command line displays *both* \n and \r\n as single newlines, your test should redirect the output to a file, and then examine the result in either a hex editor or a code editor that supports displaying line-ending characters (such as Programmer's Notepad 2). I suspect this issue may simply be the same as #9776: http://d.puremagic.com/issues/show_bug.cgi?id=9776
Comment #2 by bearophile_hugs — 2013-03-23T18:32:06Z
(In reply to comment #1) > Try converting all of the 'write' into 'stdout.rawWrite'. If I use stdout.rawWrite then the duplication of newlines (in the first program) doesn't happen.
Comment #3 by razvan.nitu1305 — 2017-09-05T12:53:39Z
This issue is the same as 9776. The decision for 9776 was to close it as WONTFIX. Applying the same procedure to this one.
Comment #4 by dfj1esp02 — 2017-09-05T13:34:33Z
*** This issue has been marked as a duplicate of issue 9776 ***
Comment #5 by razvan.nitu1305 — 2017-09-05T13:39:31Z
Since this one was reported originally, I think it would make more sense to mark 9776 as a duplicate of this one. Either way, the issues reference each other so I guess anything works.