diff options
Diffstat (limited to 'gio/gfileoutputstream.c')
-rw-r--r-- | gio/gfileoutputstream.c | 345 |
1 files changed, 0 insertions, 345 deletions
diff --git a/gio/gfileoutputstream.c b/gio/gfileoutputstream.c deleted file mode 100644 index a7864d77..00000000 --- a/gio/gfileoutputstream.c +++ /dev/null @@ -1,345 +0,0 @@ -#include <config.h> - -#include <glib.h> -#include <glib/gi18n-lib.h> -#include <gfileoutputstream.h> -#include <gseekable.h> - -static void g_file_output_stream_seekable_iface_init (GSeekableIface *iface); -static goffset g_file_output_stream_seekable_tell (GSeekable *seekable); -static gboolean g_file_output_stream_seekable_can_seek (GSeekable *seekable); -static gboolean g_file_output_stream_seekable_seek (GSeekable *seekable, - goffset offset, - GSeekType type, - GCancellable *cancellable, - GError **error); -static gboolean g_file_output_stream_seekable_can_truncate (GSeekable *seekable); -static gboolean g_file_output_stream_seekable_truncate (GSeekable *seekable, - goffset offset, - GCancellable *cancellable, - GError **error); - -G_DEFINE_TYPE_WITH_CODE (GFileOutputStream, g_file_output_stream, G_TYPE_OUTPUT_STREAM, - G_IMPLEMENT_INTERFACE (G_TYPE_SEEKABLE, - g_file_output_stream_seekable_iface_init)); - -struct _GFileOutputStreamPrivate { - int dummy; -}; - -static void -g_file_output_stream_class_init (GFileOutputStreamClass *klass) -{ - g_type_class_add_private (klass, sizeof (GFileOutputStreamPrivate)); -} - -static void -g_file_output_stream_seekable_iface_init (GSeekableIface *iface) -{ - iface->tell = g_file_output_stream_seekable_tell; - iface->can_seek = g_file_output_stream_seekable_can_seek; - iface->seek = g_file_output_stream_seekable_seek; - iface->can_truncate = g_file_output_stream_seekable_can_truncate; - iface->truncate = g_file_output_stream_seekable_truncate; -} - -static void -g_file_output_stream_init (GFileOutputStream *stream) -{ - stream->priv = G_TYPE_INSTANCE_GET_PRIVATE (stream, - G_TYPE_FILE_OUTPUT_STREAM, - GFileOutputStreamPrivate); -} - -GFileInfo * -g_file_output_stream_get_file_info (GFileOutputStream *stream, - char *attributes, - GCancellable *cancellable, - GError **error) -{ - GFileOutputStreamClass *class; - GOutputStream *output_stream; - GFileInfo *info; - - g_return_val_if_fail (G_IS_FILE_OUTPUT_STREAM (stream), NULL); - g_return_val_if_fail (stream != NULL, NULL); - - output_stream = G_OUTPUT_STREAM (stream); - - if (g_output_stream_is_closed (output_stream)) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_CLOSED, - _("Stream is already closed")); - return NULL; - } - - if (g_output_stream_has_pending (output_stream)) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_PENDING, - _("Stream has outstanding operation")); - return NULL; - } - - info = NULL; - - g_output_stream_set_pending (output_stream, TRUE); - - if (cancellable) - g_push_current_cancellable (cancellable); - - class = G_FILE_OUTPUT_STREAM_GET_CLASS (stream); - if (class->get_file_info) - info = class->get_file_info (stream, attributes, cancellable, error); - else - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - _("Stream doesn't support get_file_info")); - - if (cancellable) - g_pop_current_cancellable (cancellable); - - g_output_stream_set_pending (output_stream, FALSE); - - return info; -} - -char * -g_file_output_stream_get_etag (GFileOutputStream *stream, - GCancellable *cancellable, - GError **error) -{ - GFileOutputStreamClass *class; - GOutputStream *output_stream; - char *etag; - - g_return_val_if_fail (G_IS_FILE_OUTPUT_STREAM (stream), NULL); - g_return_val_if_fail (stream != NULL, NULL); - - output_stream = G_OUTPUT_STREAM (stream); - - if (!g_output_stream_is_closed (output_stream)) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_CLOSED, - _("Stream isn't closed yet, can't get etag")); - return NULL; - } - - if (g_output_stream_has_pending (output_stream)) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_PENDING, - _("Stream has outstanding operation")); - return NULL; - } - - etag = NULL; - - g_output_stream_set_pending (output_stream, TRUE); - - if (cancellable) - g_push_current_cancellable (cancellable); - - class = G_FILE_OUTPUT_STREAM_GET_CLASS (stream); - if (class->get_etag) - etag = class->get_etag (stream, cancellable, error); - else - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - _("etag not supported on stream")); - - if (cancellable) - g_pop_current_cancellable (cancellable); - - g_output_stream_set_pending (output_stream, FALSE); - - return etag; -} - -goffset -g_file_output_stream_tell (GFileOutputStream *stream) -{ - GFileOutputStreamClass *class; - goffset offset; - - class = G_FILE_OUTPUT_STREAM_GET_CLASS (stream); - - offset = 0; - if (class->tell) - offset = class->tell (stream); - - return offset; -} - -static goffset -g_file_output_stream_seekable_tell (GSeekable *seekable) -{ - return g_file_output_stream_tell (G_FILE_OUTPUT_STREAM (seekable)); -} - -gboolean -g_file_output_stream_can_seek (GFileOutputStream *stream) -{ - GFileOutputStreamClass *class; - gboolean can_seek; - - class = G_FILE_OUTPUT_STREAM_GET_CLASS (stream); - - can_seek = FALSE; - if (class->seek) - { - can_seek = TRUE; - if (class->can_seek) - can_seek = class->can_seek (stream); - } - - return can_seek; -} - -static gboolean -g_file_output_stream_seekable_can_seek (GSeekable *seekable) -{ - return g_file_output_stream_can_seek (G_FILE_OUTPUT_STREAM (seekable)); -} - -gboolean -g_file_output_stream_seek (GFileOutputStream *stream, - goffset offset, - GSeekType type, - GCancellable *cancellable, - GError **error) -{ - GFileOutputStreamClass *class; - GOutputStream *output_stream; - gboolean res; - - output_stream = G_OUTPUT_STREAM (stream); - class = G_FILE_OUTPUT_STREAM_GET_CLASS (stream); - - if (g_output_stream_is_closed (output_stream)) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_CLOSED, - _("Stream is already closed")); - return FALSE; - } - - if (g_output_stream_has_pending (output_stream)) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_PENDING, - _("Stream has outstanding operation")); - return FALSE; - } - - if (!class->seek) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - _("Seek not supported on stream")); - return FALSE; - } - - g_output_stream_set_pending (output_stream, TRUE); - - if (cancellable) - g_push_current_cancellable (cancellable); - - res = class->seek (stream, offset, type, cancellable, error); - - if (cancellable) - g_pop_current_cancellable (cancellable); - - g_output_stream_set_pending (output_stream, FALSE); - - return res; -} - -static gboolean -g_file_output_stream_seekable_seek (GSeekable *seekable, - goffset offset, - GSeekType type, - GCancellable *cancellable, - GError **error) -{ - return g_file_output_stream_seek (G_FILE_OUTPUT_STREAM (seekable), - offset, type, cancellable, error); -} - -gboolean -g_file_output_stream_can_truncate (GFileOutputStream *stream) -{ - GFileOutputStreamClass *class; - gboolean can_truncate; - - class = G_FILE_OUTPUT_STREAM_GET_CLASS (stream); - - can_truncate = FALSE; - if (class->truncate) - { - can_truncate = TRUE; - if (class->can_truncate) - can_truncate = class->can_truncate (stream); - } - - return can_truncate; -} - -static gboolean -g_file_output_stream_seekable_can_truncate (GSeekable *seekable) -{ - return g_file_output_stream_can_truncate (G_FILE_OUTPUT_STREAM (seekable)); -} - - -gboolean -g_file_output_stream_truncate (GFileOutputStream *stream, - goffset size, - GCancellable *cancellable, - GError **error) -{ - GFileOutputStreamClass *class; - GOutputStream *output_stream; - gboolean res; - - output_stream = G_OUTPUT_STREAM (stream); - class = G_FILE_OUTPUT_STREAM_GET_CLASS (stream); - - if (g_output_stream_is_closed (output_stream)) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_CLOSED, - _("Stream is already closed")); - return FALSE; - } - - if (g_output_stream_has_pending (output_stream)) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_PENDING, - _("Stream has outstanding operation")); - return FALSE; - } - - if (!class->truncate) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - _("Truncate not supported on stream")); - return FALSE; - } - - g_output_stream_set_pending (output_stream, TRUE); - - if (cancellable) - g_push_current_cancellable (cancellable); - - res = class->truncate (stream, size, cancellable, error); - - if (cancellable) - g_pop_current_cancellable (cancellable); - - g_output_stream_set_pending (output_stream, FALSE); - - return res; -} - -static gboolean -g_file_output_stream_seekable_truncate (GSeekable *seekable, - goffset size, - GCancellable *cancellable, - GError **error) -{ - return g_file_output_stream_truncate (G_FILE_OUTPUT_STREAM (seekable), - size, cancellable, error); -} |