reddit discussion on replacing Python in 0install

Steven Schveighoffer schveiguy at yahoo.com
Wed Jun 12 11:42:05 PDT 2013


On Wed, 12 Jun 2013 13:36:17 -0400, Jérôme M. Berger <jeberger at free.fr>
wrote:

> Denis Koroskin wrote:
>> The best solution would be for writeln() to throw on use, and I
>> think it's fairly easy to implement: just flush once after using
>> the file descriptor for the first time, and throw if it fails.
>>
>> While it doesn't cover a case where file descriptor becomes
>> non-writable during the program lifetime, it covers the most
>> common case of file descriptor not being writable at all.
>
> 	Actually, the best solution is to check if the file is writable
> before writing and *without flushing*. On Posix systems, this can be
> done with:
>
> fcntl (fd, F_GETFL) & W_OK

This is probably the better answer.

You only have to do that with FILE * initialized with fdopen.

-Steve


More information about the Digitalmars-d mailing list