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

Alex Rønne Petersen xtzgzorex at gmail.com
Wed Jun 13 02:16:02 PDT 2012


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:

* http://www.cplusplus.com/reference/clibrary/cstdio/fwrite/
* http://pubs.opengroup.org/onlinepubs/007904875/functions/fwrite.html
* http://linux.die.net/man/3/fwrite
* https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/fwrite.3.html
* http://www.unix.com/man-page/freebsd/3/fwrite/

>From none of these can I derive the reason for resetting result to 0
if size_t.max is returned.

Can anyone shed some light on this?

Thanks and regards,
Alex


More information about the phobos mailing list