[Issue 4243] New: [snn.lib] setmode doesn't set stdin/stdout to binary
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu May 27 15:32:16 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4243
Summary: [snn.lib] setmode doesn't set stdin/stdout to binary
Product: D
Version: 2.041
Platform: x86
URL: http://www.digitalmars.com/d/archives/digitalmars/D/se
tmode_again_74658.html
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: rsinfu at gmail.com
--- Comment #0 from Shin Fujishiro <rsinfu at gmail.com> 2010-05-27 15:32:13 PDT ---
setmode(stdout, O_BINARY) does not set stdout to binary mode. setmode surely
works for fopen'ed files, but does not work for standard file streams.
-------------------- test1.d
import std.c.stdio;
extern(C) int setmode(int, int);
enum O_BINARY = 0x8000;
void main()
{
string s = "\n";
// write to stdout
setmode(stdout._file, O_BINARY); // set to binary mode
fwrite(s.ptr, 1, s.length, stdout);
// write to test.dat
auto f = fopen("test.dat", "w"); // open in text mode
setmode(f._file, O_BINARY); // set to binary mode
fwrite(s.ptr, 1, s.length, f);
fclose(f);
}
--------------------
>dmd -run test1 | od -c
0000000 \r \n <-- written in text mode
0000002
>od -c test.dat
0000000 \n <-- okay
0000001
--------------------
This also does not work:
-------------------- test2.d
import std.c.stdio;
enum _IOTRAN = 0x100; // taken from DMC include/stdio.h
void main()
{
string s = "\n";
stdout._flag &= ~_IOTRAN;
fwrite(s.ptr, 1, s.length, stdout);
}
--------------------
>dmd -run test2 | od -c
0000000 \r \n <-- written in text mode
0000002
--------------------
Only this works:
-------------------- test3.d
import std.c.stdio;
void main()
{
string s = "\n";
__fhnd_info[stdout._file] &= ~FHND_TEXT;
fwrite(s.ptr, 1, s.length, stdout);
}
--------------------
>dmd -run test3 | od -c
0000000 \n <-- okay, written in binary mode
0000001
--------------------
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list