Writes buf to FILE
When return value is:
Negative: error, check errno
0: wrote no data (break)
Positive: Amount of data from buf written.