June 13, 2012 [phobos] Question about File.rawWrite() error checking | ||||
---|---|---|---|---|
| ||||
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 _______________________________________________ phobos mailing list phobos@puremagic.com http://lists.puremagic.com/mailman/listinfo/phobos |
June 13, 2012 Re: [phobos] Question about File.rawWrite() error checking | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Rønne Petersen | 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 _______________________________________________ phobos mailing list phobos@puremagic.com http://lists.puremagic.com/mailman/listinfo/phobos |
Copyright © 1999-2021 by the D Language Foundation