I have a GDataOutputStream* and now I need to close the underlying GOutputStream* manually (by calling g_output_stream_close()).

Is it safe to just cast GDataOutputStream* to GOutputStream*? Or do I need to get the underlying stream some other way?

1 Answers

Philip Withnall On Best Solutions

Yes, that’s the right way to do things:

g_autoptr(GError) local_error = NULL;
if (!g_output_stream_close (G_OUTPUT_STREAM (my_data_stream), NULL, &local_error))
    /* handle the error, for example: */
    g_warning ("Error closing stream: %s", local_error->message);