D-Programming-Language/phobos — pull request #2230 by rbanderton (2014-06-06 14:40:23+00:00)
Title: Fix Issue 6644 - std.stdio write/writef(ln) are not @trusted

https://issues.dlang.org/show_bug.cgi?id=6644
More discussion here: http://stackoverflow.com/questions/19101305/how-can-i-do-i-o-in-safe-functions-in-d

Changes I have made to get write and family callable from `@safe` code:
- Made `LockingTextWriter` and factory function `@trusted` - I didn't see anything inherently unsafe about the functions it calls to manage the lock. I'm certainly open to correction, though.
- Moved `File.write`, `File.writeln`, `File.writef` and `File.writefln` to non-member functions (UFCS). This is because member functions, even templated ones, cannot infer safety. If you do not infer safety then you can call `toString` on `@system` types (that may actually be unsafe) from `@safe` code.
- Wrapped the `stdout` global variable's usage in a `private @trusted` property that is used by `write` and friends. If this is not done they always infer to `@system` due to accessing a global variable. I'm not 100% sure this is safe to to, but with the property being private all external use of the global will still be `@system`.