tools: Check the return value of write().