[phobos] Question about File.rawWrite() error checking

Dmitry Olshansky dmitry.olsh at gmail.com
Wed Jun 13 02:20:51 PDT 2012


On 13.06.2012 13:16, Alex Rønne Petersen wrote:
> Hi,
>
> In File.rawWrite() (in std.stdio), there is the following error checking code:
>
>          auto result =
>              .fwrite(buffer.ptr, T.sizeof, buffer.length, p.handle);
>          if (result == result.max) result = 0;
>          errnoEnforce(result == buffer.length,
>                  text("Wrote ", result, " instead of ", buffer.length,
>                          " objects of type ", T.stringof, " to file `",
>                          p.name, "'"));
>
> Call me silly, but I don't understand the `result == result.max` check. See:

Obviously it counts on fwrite to return -1 on error. I'd say it's a 
carry over from when code (supposedly) used POSIX write call directly.


-- 
Dmitry Olshansky



More information about the phobos mailing list