/* Returns: TRUE on success, FALSE if there was an error  */
gboolean g_output_stream_write_all(GOutputStream *stream, const void *buffer, gsize count, gsize *bytes_written, GCancellable *cancellable, GError **error)
/* Returns: TRUE on success, FALSE if there was an error  */
gboolean g_output_stream_write_all(GOutputStream *stream, const void *buffer, gsize count, gsize *bytes_written, GCancellable *cancellable, GError **error)
{
  gsize _bytes_written;
  gssize res;
  g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE);
  g_return_val_if_fail (buffer != NULL, FALSE);
  _bytes_written = 0;
  while (_bytes_written < count)
    {
      res = g_output_stream_write (stream, (char *)buffer + _bytes_written, count - _bytes_written,
				   cancellable, error);
      if (res == -1)
	{
	  if (bytes_written)
	    *bytes_written = _bytes_written;
	  return FALSE;
	}
      if (res == 0)
	g_warning ("Write returned zero without error");
      _bytes_written += res;
    }
  if (bytes_written)
    *bytes_written = _bytes_written;
  return TRUE;
}