/* Returns: TRUE on success, FALSE if there was an error  */
gboolean g_input_stream_read_all(GInputStream *stream, void *buffer, gsize count, gsize *bytes_read, GCancellable *cancellable, GError **error)
/* Returns: TRUE on success, FALSE if there was an error  */
gboolean g_input_stream_read_all(GInputStream *stream, void *buffer, gsize count, gsize *bytes_read, GCancellable *cancellable, GError **error)
{
  gsize _bytes_read;
  gssize res;
  g_return_val_if_fail (G_IS_INPUT_STREAM (stream), FALSE);
  g_return_val_if_fail (buffer != NULL, FALSE);
  _bytes_read = 0;
  while (_bytes_read < count)
    {
      res = g_input_stream_read (stream, (char *)buffer + _bytes_read, count - _bytes_read,
				 cancellable, error);
      if (res == -1)
	{
	  if (bytes_read)
	    *bytes_read = _bytes_read;
	  return FALSE;
	}
      if (res == 0)
	break;
      _bytes_read += res;
    }
  if (bytes_read)
    *bytes_read = _bytes_read;
  return TRUE;
}