Thread overview
Need to 'write' exactly
Sep 12, 2010
Nick Sabalausky
Sep 12, 2010
Andrej Mitrovic
Sep 12, 2010
Nick Sabalausky
September 12, 2010
I'm outputting some stuff to stdout with the write* functions, but with what I'm doing at the moment I need complete control over each byte that gets output. On windows, write auto-converts \n to \r\n, which is normally good, but this time I need to get around that and output it just as-is. How can I do that? Is there a lower level function that's guaranteed not to interact poorly with write (ie, no potential for any weird buffering-race issues)?

Also, are there any other situations where any of the write functions might alter the specific bytes passed in?


September 12, 2010
Have you tried using rawWrite ? There's a unittest in the definition which looks like something you need:

    unittest
    {
        auto f = File("deleteme", "w");
        scope(exit) std.file.remove("deleteme");
        f.rawWrite("\r\n\n\r\n");
        f.close();
        assert(std.file.read("deleteme") == "\r\n\n\r\n");
    }

On Sun, Sep 12, 2010 at 10:07 PM, Nick Sabalausky <a@a.a> wrote:
> I'm outputting some stuff to stdout with the write* functions, but with what I'm doing at the moment I need complete control over each byte that gets output. On windows, write auto-converts \n to \r\n, which is normally good, but this time I need to get around that and output it just as-is. How can I do that? Is there a lower level function that's guaranteed not to interact poorly with write (ie, no potential for any weird buffering-race issues)?
>
> Also, are there any other situations where any of the write functions might alter the specific bytes passed in?
>
>
>
September 12, 2010
"Andrej Mitrovic" <andrej.mitrovich@gmail.com> wrote in message news:mailman.179.1284322385.858.digitalmars-d-learn@puremagic.com...
> Have you tried using rawWrite ? There's a unittest in the definition which looks like something you need:
>
>    unittest
>    {
>        auto f = File("deleteme", "w");
>        scope(exit) std.file.remove("deleteme");
>        f.rawWrite("\r\n\n\r\n");
>        f.close();
>        assert(std.file.read("deleteme") == "\r\n\n\r\n");
>    }
>

Leave it to me to overlook the obvious :)  This seems to work:

-------------------------------------------------
import std.stdio;
import std.string;
void main()
{
    // Writes "A\rB\r\nC" on windows
    //write("A\rB\nC");

    // Writes "A\rB\nC"
    stdout.rawWrite("A\rB\nC");

    // format doesn't mess it up either, which is good
    stdout.rawWrite("A\rB\nC".format());
    stdout.rawWrite("%s".format("A\rB\nC"));
}
-------------------------------------------------

That wouldn't potentially interfere with any sort of buffering in write*, would it? I assume any buffering would be at or below the "stdout" level, rather than in the "write*" functions, but figure I should ask.