1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
24 #include "gseekable.h"
30 * @short_description: Stream seeking interface
32 * @see_also: #GInputStream, #GOutputStream
34 * #GSeekable is implemented by streams (implementations of
35 * #GInputStream or #GOutputStream) that support seeking.
39 typedef GSeekableIface GSeekableInterface
;
40 G_DEFINE_INTERFACE (GSeekable
, g_seekable
, G_TYPE_OBJECT
)
43 g_seekable_default_init (GSeekableInterface
*iface
)
49 * @seekable: a #GSeekable.
51 * Tells the current position within the stream.
53 * Returns: the offset from the beginning of the buffer.
56 g_seekable_tell (GSeekable
*seekable
)
58 GSeekableIface
*iface
;
60 g_return_val_if_fail (G_IS_SEEKABLE (seekable
), 0);
62 iface
= G_SEEKABLE_GET_IFACE (seekable
);
64 return (* iface
->tell
) (seekable
);
68 * g_seekable_can_seek:
69 * @seekable: a #GSeekable.
71 * Tests if the stream supports the #GSeekableIface.
73 * Returns: %TRUE if @seekable can be seeked. %FALSE otherwise.
76 g_seekable_can_seek (GSeekable
*seekable
)
78 GSeekableIface
*iface
;
80 g_return_val_if_fail (G_IS_SEEKABLE (seekable
), FALSE
);
82 iface
= G_SEEKABLE_GET_IFACE (seekable
);
84 return (* iface
->can_seek
) (seekable
);
89 * @seekable: a #GSeekable.
90 * @offset: a #goffset.
91 * @type: a #GSeekType.
92 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
93 * @error: a #GError location to store the error occurring, or %NULL to
96 * Seeks in the stream by the given @offset, modified by @type.
98 * If @cancellable is not %NULL, then the operation can be cancelled by
99 * triggering the cancellable object from another thread. If the operation
100 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
102 * Returns: %TRUE if successful. If an error
103 * has occurred, this function will return %FALSE and set @error
104 * appropriately if present.
107 g_seekable_seek (GSeekable
*seekable
,
110 GCancellable
*cancellable
,
113 GSeekableIface
*iface
;
115 g_return_val_if_fail (G_IS_SEEKABLE (seekable
), FALSE
);
117 iface
= G_SEEKABLE_GET_IFACE (seekable
);
119 return (* iface
->seek
) (seekable
, offset
, type
, cancellable
, error
);
123 * g_seekable_can_truncate:
124 * @seekable: a #GSeekable.
126 * Tests if the stream can be truncated.
128 * Returns: %TRUE if the stream can be truncated, %FALSE otherwise.
131 g_seekable_can_truncate (GSeekable
*seekable
)
133 GSeekableIface
*iface
;
135 g_return_val_if_fail (G_IS_SEEKABLE (seekable
), FALSE
);
137 iface
= G_SEEKABLE_GET_IFACE (seekable
);
139 return (* iface
->can_truncate
) (seekable
);
143 * g_seekable_truncate:
144 * @seekable: a #GSeekable.
145 * @offset: a #goffset.
146 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
147 * @error: a #GError location to store the error occurring, or %NULL to
150 * Truncates a stream with a given #offset.
152 * If @cancellable is not %NULL, then the operation can be cancelled by
153 * triggering the cancellable object from another thread. If the operation
154 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
155 * operation was partially finished when the operation was cancelled the
156 * partial result will be returned, without an error.
158 * Virtual: truncate_fn
159 * Returns: %TRUE if successful. If an error
160 * has occurred, this function will return %FALSE and set @error
161 * appropriately if present.
164 g_seekable_truncate (GSeekable
*seekable
,
166 GCancellable
*cancellable
,
169 GSeekableIface
*iface
;
171 g_return_val_if_fail (G_IS_SEEKABLE (seekable
), FALSE
);
173 iface
= G_SEEKABLE_GET_IFACE (seekable
);
175 return (* iface
->truncate_fn
) (seekable
, offset
, cancellable
, error
);