static int stream_close (CamelStream *stream) { CamelStreamVFS *stream_vfs = CAMEL_STREAM_VFS (stream); GError *error = NULL; g_return_val_if_fail (CAMEL_IS_STREAM_VFS (stream) && stream_vfs != NULL, -1); g_return_val_if_fail (stream_vfs->stream != NULL, -1); g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream_vfs->stream) || G_IS_INPUT_STREAM (stream_vfs->stream), -1); if (G_IS_OUTPUT_STREAM (stream_vfs->stream)) g_output_stream_close (G_OUTPUT_STREAM (stream_vfs->stream), NULL, &error); else g_input_stream_close (G_INPUT_STREAM (stream_vfs->stream), NULL, &error); if (error) { g_warning ("%s", error->message); g_error_free (error); return -1; } g_object_unref (stream_vfs->stream); stream_vfs->stream = NULL; return 0; }
static gboolean gst_gio_base_sink_event (GstBaseSink * base_sink, GstEvent * event) { GstGioBaseSink *sink = GST_GIO_BASE_SINK (base_sink); GstFlowReturn ret = GST_FLOW_OK; if (sink->stream == NULL) return TRUE; switch (GST_EVENT_TYPE (event)) { case GST_EVENT_SEGMENT: if (G_IS_OUTPUT_STREAM (sink->stream)) { const GstSegment *segment; gst_event_parse_segment (event, &segment); if (segment->format != GST_FORMAT_BYTES) { GST_WARNING_OBJECT (sink, "ignored SEGMENT event in %s format", gst_format_get_name (segment->format)); break; } if (GST_GIO_STREAM_IS_SEEKABLE (sink->stream)) { ret = gst_gio_seek (sink, G_SEEKABLE (sink->stream), segment->start, sink->cancel); if (ret == GST_FLOW_OK) sink->position = segment->start; } else { ret = GST_FLOW_NOT_SUPPORTED; } } break; case GST_EVENT_EOS: case GST_EVENT_FLUSH_START: if (G_IS_OUTPUT_STREAM (sink->stream)) { gboolean success; GError *err = NULL; success = g_output_stream_flush (sink->stream, sink->cancel, &err); if (!success && !gst_gio_error (sink, "g_output_stream_flush", &err, &ret)) { GST_ELEMENT_ERROR (sink, RESOURCE, WRITE, (NULL), ("flush failed: %s", err->message)); g_clear_error (&err); } } break; default: break; } if (ret == GST_FLOW_OK) return GST_BASE_SINK_CLASS (parent_class)->event (base_sink, event); else { gst_event_unref (event); return FALSE; } }
static void get_callback (SoupSession *session, SoupMessage *msg, SeahorseHKPOperation *hop) { GError *err = NULL; const gchar *start; const gchar *end; GOutputStream *output; const gchar *text; gboolean ret; guint len; gsize written; if (hop->cancelling) return; if (SOUP_MESSAGE_IS_ERROR (msg)) { fail_hkp_operation (hop, msg, NULL); return; } end = text = msg->response_body->data; len = msg->response_body->length; for (;;) { len -= end - text; text = end; if(!detect_key (text, len, &start, &end)) break; /* Any key blocks get written to our result data */ output = seahorse_operation_get_result (SEAHORSE_OPERATION (hop)); g_return_if_fail (G_IS_OUTPUT_STREAM (output)); ret = g_output_stream_write_all (output, start, end - start, &written, NULL, &err) && g_output_stream_write_all (output, "\n", 1, &written, NULL, &err) && g_output_stream_flush (output, NULL, &err); if (!ret) { seahorse_operation_mark_done (SEAHORSE_OPERATION (hop), FALSE, err); return; } } if (--hop->requests <= 0) { output = seahorse_operation_get_result (SEAHORSE_OPERATION (hop)); g_return_if_fail (G_IS_OUTPUT_STREAM (output)); g_output_stream_close (output, NULL, &err); seahorse_operation_mark_done (SEAHORSE_OPERATION (hop), FALSE, err); } else { seahorse_operation_mark_progress_full (SEAHORSE_OPERATION (hop), _("Retrieving keys..."), hop->requests, hop->total); } }
/** * ggit_patch_to_stream: * @patch: a #GgitPatch. * @stream: a #GOutputStream. * @error: a #GError for error reporting, or %NULL. * * Write the contents of a patch to the provided stream. * * Returns: %TRUE if the patch was written successfully, %FALSE otherwise. * **/ gboolean ggit_patch_to_stream (GgitPatch *patch, GOutputStream *stream, GError **error) { PatchToStream info; gint ret; g_return_val_if_fail (patch != NULL, FALSE); g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); info.stream = stream; info.error = error; ret = git_patch_print (patch->patch, patch_to_stream, &info); if (ret != GIT_OK) { if (error != NULL && *error == NULL) { _ggit_error_set (error, ret); } return FALSE; } return TRUE; }
/** * camel_stream_vfs_is_writable: * @stream_vfs: a #CamelStreamVFS instance * * Returns whether is the underlying stream writable or not. **/ gboolean camel_stream_vfs_is_writable (CamelStreamVFS *stream_vfs) { g_return_val_if_fail (stream_vfs != NULL, FALSE); g_return_val_if_fail (stream_vfs->stream != NULL, FALSE); return G_IS_OUTPUT_STREAM (stream_vfs->stream); }
/* Called by gpgme to close a file */ static void output_release (void *handle) { GOutputStream* output = handle; g_return_if_fail (G_IS_OUTPUT_STREAM (output)); g_object_unref (output); }
void lsm_dom_document_save_to_stream (LsmDomDocument *document, GOutputStream *stream, GError **error) { g_return_if_fail (LSM_IS_DOM_DOCUMENT (document)); g_return_if_fail (G_IS_OUTPUT_STREAM (stream)); lsm_dom_node_write_to_stream (LSM_DOM_NODE (document), stream, error); }
gboolean byzanz_serialize (GOutputStream * stream, guint64 msecs, cairo_surface_t * surface, const cairo_region_t * region, GCancellable * cancellable, GError ** error) { guint i, stride; cairo_rectangle_int_t rect, extents; guchar *data; guint32 n; int y, n_rects; g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE); g_return_val_if_fail ((surface == NULL) == (region == NULL), FALSE); g_return_val_if_fail (region == NULL || !cairo_region_is_empty (region), FALSE); if (!g_output_stream_write_all (stream, &msecs, sizeof (guint64), NULL, cancellable, error)) return FALSE; if (surface == 0) { n = 0; return g_output_stream_write_all (stream, &n, sizeof (guint32), NULL, cancellable, error); } n = n_rects = cairo_region_num_rectangles (region); if (!g_output_stream_write_all (stream, &n, sizeof (guint32), NULL, cancellable, error)) return FALSE; for (i = 0; i < n; i++) { gint32 ints[4]; cairo_region_get_rectangle (region, i, &rect); ints[0] = rect.x, ints[1] = rect.y, ints[2] = rect.width, ints[3] = rect.height; g_assert (sizeof (ints) == 16); if (!g_output_stream_write_all (stream, ints, sizeof (ints), NULL, cancellable, error)) return FALSE; } stride = cairo_image_surface_get_stride (surface); cairo_region_get_extents (region, &extents); for (i = 0; i < n; i++) { cairo_region_get_rectangle (region, i, &rect); data = cairo_image_surface_get_data (surface) + stride * (rect.y - extents.y) + sizeof (guint32) * (rect.x - extents.x); for (y = 0; y < rect.height; y++) { if (!g_output_stream_write_all (G_OUTPUT_STREAM (stream), data, rect.width * sizeof (guint32), NULL, cancellable, error)) return FALSE; data += stride; } } return TRUE; }
static GstFlowReturn gst_gio_base_sink_render (GstBaseSink * base_sink, GstBuffer * buffer) { GstGioBaseSink *sink = GST_GIO_BASE_SINK (base_sink); gssize written; GstMapInfo map; gboolean success; GError *err = NULL; g_return_val_if_fail (G_IS_OUTPUT_STREAM (sink->stream), GST_FLOW_ERROR); gst_buffer_map (buffer, &map, GST_MAP_READ); GST_LOG_OBJECT (sink, "writing %" G_GSIZE_FORMAT " bytes to offset %" G_GUINT64_FORMAT, map.size, sink->position); written = g_output_stream_write (sink->stream, map.data, map.size, sink->cancel, &err); gst_buffer_unmap (buffer, &map); success = (written >= 0); if (G_UNLIKELY (success && written < map.size)) { /* FIXME: Can this happen? Should we handle it gracefully? gnomevfssink * doesn't... */ GST_ELEMENT_ERROR (sink, RESOURCE, WRITE, (NULL), ("Could not write to stream: (short write, only %" G_GSSIZE_FORMAT " bytes of %" G_GSIZE_FORMAT " bytes written)", written, map.size)); return GST_FLOW_ERROR; } if (success) { sink->position += written; return GST_FLOW_OK; } else { GstFlowReturn ret; if (!gst_gio_error (sink, "g_output_stream_write", &err, &ret)) { if (GST_GIO_ERROR_MATCHES (err, NO_SPACE)) { GST_ELEMENT_ERROR (sink, RESOURCE, NO_SPACE_LEFT, (NULL), ("Could not write to stream: %s", err->message)); } else { GST_ELEMENT_ERROR (sink, RESOURCE, WRITE, (NULL), ("Could not write to stream: %s", err->message)); } g_clear_error (&err); } return ret; } }
static GIOStream * my_io_stream_new (GInputStream *input_stream, GOutputStream *output_stream) { MyIOStream *stream; g_return_val_if_fail (G_IS_INPUT_STREAM (input_stream), NULL); g_return_val_if_fail (G_IS_OUTPUT_STREAM (output_stream), NULL); stream = MY_IO_STREAM (g_object_new (MY_TYPE_IO_STREAM, NULL)); stream->input_stream = g_object_ref (input_stream); stream->output_stream = g_object_ref (output_stream); return G_IO_STREAM (stream); }
void arv_dom_node_write_to_stream (ArvDomNode *self, GOutputStream *stream, GError **error) { ArvDomNodeClass *node_class; g_return_if_fail (ARV_IS_DOM_NODE (self)); g_return_if_fail (G_IS_OUTPUT_STREAM (stream)); node_class = ARV_DOM_NODE_GET_CLASS (self); if (node_class->write_to_stream != NULL) node_class->write_to_stream (self, stream, error); }
/** * tmpl_template_expand: * @self: A TmplTemplate. * @stream: a #GOutputStream to write the results to * @scope: (nullable): A #TmplScope containing state for the template, or %NULL. * @cancellable: (nullable): An optional cancellable for the operation. * @error: A location for a #GError, or %NULL. * * Expands a template into @stream using the @scope provided. * * @scope should have all of the variables set that are required to expand * the template, or you will get a symbol reference error and %FALSE will * be returned. * * To set a symbol value, get the symbol with tmpl_scope_get() and assign * a value using tmpl_scope_assign_value() or similar methods. * * Returns: %TRUE if successful, otherwise %FALSE and @error is set. */ gboolean tmpl_template_expand (TmplTemplate *self, GOutputStream *stream, TmplScope *scope, GCancellable *cancellable, GError **error) { TmplTemplatePrivate *priv = tmpl_template_get_instance_private (self); TmplTemplateExpandState state = { 0 }; TmplScope *local_scope = NULL; g_return_val_if_fail (TMPL_IS_TEMPLATE (self), FALSE); g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE); g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE); if (priv->parser == NULL) { g_set_error (error, TMPL_ERROR, TMPL_ERROR_INVALID_STATE, _("Must parse template before expanding")); return FALSE; } if (scope == NULL) scope = local_scope = tmpl_scope_new (); state.root = tmpl_parser_get_root (priv->parser); state.self = self; state.output = g_string_new (NULL); state.result = TRUE; state.error = error; state.scope = scope; tmpl_node_visit_children (state.root, tmpl_template_expand_visitor, &state); if (state.result != FALSE) state.result = g_output_stream_write_all (stream, state.output->str, state.output->len, NULL, cancellable, error); g_string_free (state.output, TRUE); if (local_scope != NULL) tmpl_scope_unref (local_scope); return state.result; }
static void test_io_stream_properties (NiceAddress *addr) { NiceAgent *agent; guint stream_id; GIOStream *io_stream; GInputStream *input_stream; GOutputStream *output_stream; agent = nice_agent_new_reliable (NULL, NICE_COMPATIBILITY_RFC5245); nice_agent_add_local_address (agent, addr); stream_id = nice_agent_add_stream (agent, 1); /* Try building an I/O stream around it. */ io_stream = nice_agent_get_io_stream (agent, stream_id, 1); g_assert (G_IS_IO_STREAM (io_stream)); g_assert (NICE_IS_IO_STREAM (io_stream)); /* Check various initial properties. */ g_assert (!g_io_stream_is_closed (G_IO_STREAM (io_stream))); g_assert (!g_io_stream_has_pending (G_IO_STREAM (io_stream))); /* Check the input stream’s properties. */ input_stream = g_io_stream_get_input_stream (G_IO_STREAM (io_stream)); g_assert (G_IS_INPUT_STREAM (input_stream)); g_assert (NICE_IS_INPUT_STREAM (input_stream)); g_assert (!g_input_stream_is_closed (input_stream)); g_assert (!g_input_stream_has_pending (input_stream)); /* Check the output stream’s properties. */ output_stream = g_io_stream_get_output_stream (G_IO_STREAM (io_stream)); g_assert (G_IS_OUTPUT_STREAM (output_stream)); g_assert (NICE_IS_OUTPUT_STREAM (output_stream)); g_assert (!g_output_stream_is_closing (output_stream)); g_assert (!g_output_stream_is_closed (output_stream)); g_assert (!g_output_stream_has_pending (output_stream)); /* Remove the component and check that the I/O streams close. */ nice_agent_remove_stream (agent, stream_id); g_assert (g_io_stream_is_closed (G_IO_STREAM (io_stream))); g_assert (g_input_stream_is_closed (input_stream)); g_assert (g_output_stream_is_closed (output_stream)); g_object_unref (io_stream); g_object_unref (agent); }
gpgme_data_t seahorse_gpgme_data_output (GOutputStream* output) { gpgme_error_t gerr; gpgme_data_t ret = NULL; g_return_val_if_fail (G_IS_OUTPUT_STREAM (output), NULL); gerr = gpgme_data_new_from_cbs (&ret, &output_cbs, output); if (!GPG_IS_OK (gerr)) return NULL; g_object_ref (output); return ret; }
static gboolean gst_gio_base_sink_stop (GstBaseSink * base_sink) { GstGioBaseSink *sink = GST_GIO_BASE_SINK (base_sink); GstGioBaseSinkClass *klass = GST_GIO_BASE_SINK_GET_CLASS (sink); gboolean success; GError *err = NULL; if (klass->close_on_stop && G_IS_OUTPUT_STREAM (sink->stream)) { GST_DEBUG_OBJECT (sink, "closing stream"); /* FIXME: can block but unfortunately we can't use async operations * here because they require a running main loop */ success = g_output_stream_close (sink->stream, sink->cancel, &err); if (!success && !gst_gio_error (sink, "g_output_stream_close", &err, NULL)) { GST_ELEMENT_WARNING (sink, RESOURCE, CLOSE, (NULL), ("gio_output_stream_close failed: %s", err->message)); g_clear_error (&err); } else if (!success) { GST_ELEMENT_WARNING (sink, RESOURCE, CLOSE, (NULL), ("g_output_stream_close failed")); } else { GST_DEBUG_OBJECT (sink, "g_outut_stream_close succeeded"); } g_object_unref (sink->stream); sink->stream = NULL; } else { success = g_output_stream_flush (sink->stream, sink->cancel, &err); if (!success && !gst_gio_error (sink, "g_output_stream_flush", &err, NULL)) { GST_ELEMENT_WARNING (sink, RESOURCE, CLOSE, (NULL), ("gio_output_stream_flush failed: %s", err->message)); g_clear_error (&err); } else if (!success) { GST_ELEMENT_WARNING (sink, RESOURCE, CLOSE, (NULL), ("g_output_stream_flush failed")); } else { GST_DEBUG_OBJECT (sink, "g_outut_stream_flush succeeded"); } g_object_unref (sink->stream); sink->stream = NULL; } return TRUE; }
/** * gb_project_format_save_async: * @format: (in): A #GbProjectFormat. * @stream: (in): A #GOutputStream. * @cancellable: (in) (allow-none): A #GCancellable or %NULL. * @callback: (in): A callback to notify of completion. * @user_data: (in): User data for @callback. * * Asynchronously saves @project as to @stream using the format implemented * by @format. The default format is a JSON encoded document. */ void gb_project_format_save_async (GbProjectFormat *format, GbProject *project, GOutputStream *stream, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { ENTRY; g_return_if_fail(GB_IS_PROJECT_FORMAT(format)); g_return_if_fail(G_IS_OUTPUT_STREAM(stream)); g_return_if_fail(!cancellable || G_IS_CANCELLABLE(cancellable)); g_return_if_fail(callback != NULL); GB_PROJECT_FORMAT_GET_CLASS(format)->save_async(format, project, stream, cancellable, callback, user_data); EXIT; }
/* Called by gpgme to read data */ static ssize_t output_write(void *handle, const void *buffer, size_t size) { GOutputStream* output = handle; GError *err = NULL; gsize written; g_return_val_if_fail (G_IS_OUTPUT_STREAM (output), -1); if (!g_output_stream_write_all (output, buffer, size, &written, NULL, &err)) return handle_gio_error (err); if (!g_output_stream_flush (output, NULL, &err)) return handle_gio_error (err); return written; }
void gitg_io_set_output (GitgIO *io, GOutputStream *stream) { g_return_if_fail (GITG_IS_IO (io)); g_return_if_fail (G_IS_OUTPUT_STREAM (stream)); if (io->priv->output) { g_object_unref (io->priv->output); io->priv->output = NULL; } if (stream) { io->priv->output = g_object_ref (stream); } }
/** * camel_stream_vfs_new_with_stream: * @stream: a GInputStream or GOutputStream instance * * Creates a new fs stream using the given gio stream @stream as the * backing store. When the stream is destroyed, the file descriptor * will be closed. This will not increase reference counter on the stream. * * Returns a new #CamelStreamVFS **/ CamelStream * camel_stream_vfs_new_with_stream (GObject *stream) { CamelStreamVFS *stream_vfs; errno = EINVAL; if (!stream) return NULL; g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream) || G_IS_INPUT_STREAM (stream), NULL); errno = 0; stream_vfs = CAMEL_STREAM_VFS (camel_object_new (camel_stream_vfs_get_type ())); stream_vfs->stream = stream; return CAMEL_STREAM (stream_vfs); }
static ssize_t stream_write (CamelStream *stream, const char *buffer, size_t n) { gssize nwritten; GError *error = NULL; CamelStreamVFS *stream_vfs = CAMEL_STREAM_VFS (stream); g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream_vfs->stream), 0); nwritten = g_output_stream_write (G_OUTPUT_STREAM (stream_vfs->stream), buffer, n, NULL, &error); if (error) { g_warning ("%s", error->message); g_error_free (error); } return nwritten; }
gboolean gimp_levels_config_save_cruft (GimpLevelsConfig *config, GOutputStream *output, GError **error) { GString *string; gsize bytes_written; gint i; g_return_val_if_fail (GIMP_IS_LEVELS_CONFIG (config), FALSE); g_return_val_if_fail (G_IS_OUTPUT_STREAM (output), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); string = g_string_new ("# GIMP Levels File\n"); for (i = 0; i < 5; i++) { gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; g_string_append_printf (string, "%d %d %d %d %s\n", (gint) (config->low_input[i] * 255.999), (gint) (config->high_input[i] * 255.999), (gint) (config->low_output[i] * 255.999), (gint) (config->high_output[i] * 255.999), g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", config->gamma[i])); } if (! g_output_stream_write_all (output, string->str, string->len, &bytes_written, NULL, error) || bytes_written != string->len) { g_prefix_error (error, _("Writing levels file failed: ")); g_string_free (string, TRUE); return FALSE; } g_string_free (string, TRUE); return TRUE; }
static int stream_flush (CamelStream *stream) { CamelStreamVFS *stream_vfs = CAMEL_STREAM_VFS (stream); GError *error = NULL; g_return_val_if_fail (CAMEL_IS_STREAM_VFS (stream) && stream_vfs != NULL, -1); g_return_val_if_fail (stream_vfs->stream != NULL, -1); g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream_vfs->stream), -1); g_output_stream_flush (G_OUTPUT_STREAM (stream_vfs->stream), NULL, &error); if (error) { g_warning ("%s", error->message); g_error_free (error); return -1; } return 0; }
/** * gimp_config_serialize_to_stream: * @config: a #GObject that implements the #GimpConfigInterface. * @output: the #GOutputStream to write the configuration to. * @header: optional file header (must be ASCII only) * @footer: optional file footer (must be ASCII only) * @data: user data passed to the serialize implementation. * @error: return location for a possible error * * Serializes the object properties of @config to the stream specified * by @output. * * Return value: %TRUE if serialization succeeded, %FALSE otherwise. * * Since: 2.10 **/ gboolean gimp_config_serialize_to_stream (GimpConfig *config, GOutputStream *output, const gchar *header, const gchar *footer, gpointer data, GError **error) { GimpConfigWriter *writer; g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE); g_return_val_if_fail (G_IS_OUTPUT_STREAM (output), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); writer = gimp_config_writer_new_stream (output, header, error); if (!writer) return FALSE; GIMP_CONFIG_GET_INTERFACE (config)->serialize (config, writer, data); return gimp_config_writer_finish (writer, footer, error); }
static void save_snapshot_replace_cb (GFile *snapshot_file, GAsyncResult *result, GSimpleAsyncResult *simple) { GObject *object; SaveContext *context; GFileOutputStream *output_stream; GError *local_error = NULL; context = g_simple_async_result_get_op_res_gpointer (simple); /* Output stream might be NULL, so don't use cast macro. */ output_stream = g_file_replace_finish ( snapshot_file, result, &local_error); context->output_stream = (GOutputStream *) output_stream; if (local_error != NULL) { g_warn_if_fail (output_stream == NULL); g_simple_async_result_take_error (simple, local_error); g_simple_async_result_complete (simple); g_object_unref (simple); return; } g_return_if_fail (G_IS_OUTPUT_STREAM (output_stream)); /* g_async_result_get_source_object() returns a new reference. */ object = g_async_result_get_source_object (G_ASYNC_RESULT (simple)); /* Extract a MIME message from the composer. */ e_msg_composer_get_message_draft ( E_MSG_COMPOSER (object), G_PRIORITY_DEFAULT, context->cancellable, (GAsyncReadyCallback) save_snapshot_get_message_cb, simple); g_object_unref (object); }
gboolean byzanz_serialize_header (GOutputStream * stream, guint width, guint height, GCancellable * cancellable, GError ** error) { guint32 w, h; guchar endian; g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE); g_return_val_if_fail (width <= G_MAXUINT32, FALSE); g_return_val_if_fail (height <= G_MAXUINT32, FALSE); w = width; h = height; endian = byte_order_to_uchar (); return g_output_stream_write_all (stream, IDENTIFICATION, strlen (IDENTIFICATION), NULL, cancellable, error) && g_output_stream_write_all (stream, &endian, sizeof (guchar), NULL, cancellable, error) && g_output_stream_write_all (stream, &w, sizeof (guint32), NULL, cancellable, error) && g_output_stream_write_all (stream, &h, sizeof (guint32), NULL, cancellable, error); }
/** * gimp_config_writer_new_stream: * @output: a #GOutputStream * @header: text to include as comment at the top of the file * @error: return location for errors * * Creates a new #GimpConfigWriter and sets it up to write to * @output. * * Return value: a new #GimpConfigWriter or %NULL in case of an error * * Since: GIMP 2.10 **/ GimpConfigWriter * gimp_config_writer_new_stream (GOutputStream *output, const gchar *header, GError **error) { GimpConfigWriter *writer; g_return_val_if_fail (G_IS_OUTPUT_STREAM (output), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); writer = g_slice_new0 (GimpConfigWriter); writer->output = g_object_ref (output); writer->buffer = g_string_new (NULL); if (header) { gimp_config_writer_comment (writer, header); gimp_config_writer_linefeed (writer); } return writer; }
/* Called from gpgme to seek a file */ static off_t output_seek (void *handle, off_t offset, int whence) { GSeekable *seek; GSeekType from; GError *err = NULL; GOutputStream* output = handle; g_return_val_if_fail (G_IS_OUTPUT_STREAM (output), -1); if (!G_IS_SEEKABLE (output)) { errno = EOPNOTSUPP; return -1; } switch(whence) { case SEEK_SET: from = G_SEEK_SET; break; case SEEK_CUR: from = G_SEEK_CUR; break; case SEEK_END: from = G_SEEK_END; break; default: g_assert_not_reached(); break; }; seek = G_SEEKABLE (output); if (!g_seekable_seek (seek, offset, from, NULL, &err)) return handle_gio_error (err); return offset; }
static gboolean gst_gio_base_sink_start (GstBaseSink * base_sink) { GstGioBaseSink *sink = GST_GIO_BASE_SINK (base_sink); GstGioBaseSinkClass *gbsink_class = GST_GIO_BASE_SINK_GET_CLASS (sink); sink->position = 0; /* FIXME: This will likely block */ sink->stream = gbsink_class->get_stream (sink); if (G_UNLIKELY (!G_IS_OUTPUT_STREAM (sink->stream))) { GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("No output stream provided by subclass")); return FALSE; } else if (G_UNLIKELY (g_output_stream_is_closed (sink->stream))) { GST_ELEMENT_ERROR (sink, LIBRARY, FAILED, (NULL), ("Output stream is already closed")); return FALSE; } GST_DEBUG_OBJECT (sink, "started sink"); return TRUE; }
gboolean gimp_output_stream_vprintf (GOutputStream *stream, gsize *bytes_written, GCancellable *cancellable, GError **error, const gchar *format, va_list args) { gchar *text; gboolean success; g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE); g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (stream), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); g_return_val_if_fail (format != NULL, FALSE); text = g_strdup_vprintf (format, args); success = g_output_stream_write_all (stream, text, strlen (text), bytes_written, cancellable, error); g_free (text); return success; }
* * On error -1 is returned and @error is set accordingly. * * Return value: Number of bytes written, or -1 on error **/ gssize g_output_stream_write (GOutputStream *stream, const void *buffer, gsize count, GCancellable *cancellable, GError **error) { GOutputStreamClass *class; gssize res; g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), -1); g_return_val_if_fail (buffer != NULL, 0); if (count == 0) return 0; if (((gssize) count) < 0) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, _("Too large count value passed to %s"), G_STRFUNC); return -1; } class = G_OUTPUT_STREAM_GET_CLASS (stream); if (class->write_fn == NULL)