Add new error codes for when compilation fails and make compilation error
[platform/upstream/glib.git] / gio / gseekable.c
1 /* GIO - GLib Input, Output and Streaming Library
2  * 
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  *
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.
9  *
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.
14  *
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.
19  *
20  * Author: Alexander Larsson <alexl@redhat.com>
21  */
22
23 #include <config.h>
24 #include "gseekable.h"
25 #include "glibintl.h"
26
27 #include "gioalias.h"
28
29 /**
30  * SECTION:gseekable
31  * @short_description: Stream seeking interface
32  * @see_also: #GInputStream, #GOutputStream
33  * 
34  * #GSeekable is implemented by streams (implementations of 
35  * #GInputStream or #GOutputStream) that support seeking.
36  * 
37  **/
38
39
40 static void g_seekable_base_init (gpointer g_class);
41
42
43 GType
44 g_seekable_get_type (void)
45 {
46   static GType seekable_type = 0;
47
48   if (!seekable_type)
49     {
50       static const GTypeInfo seekable_info =
51       {
52         sizeof (GSeekableIface), /* class_size */
53         g_seekable_base_init,   /* base_init */
54         NULL,           /* base_finalize */
55         NULL,
56         NULL,           /* class_finalize */
57         NULL,           /* class_data */
58         0,
59         0,              /* n_preallocs */
60         NULL
61       };
62
63       seekable_type =
64         g_type_register_static (G_TYPE_INTERFACE, I_("GSeekable"),
65                                 &seekable_info, 0);
66
67       g_type_interface_add_prerequisite (seekable_type, G_TYPE_OBJECT);
68     }
69
70   return seekable_type;
71 }
72
73 static void
74 g_seekable_base_init (gpointer g_class)
75 {
76 }
77
78 /**
79  * g_seekable_tell:
80  * @seekable: a #GSeekable.
81  * 
82  * Tells the current position within the stream.
83  * 
84  * Returns: the offset from the beginning of the buffer.
85  **/
86 goffset
87 g_seekable_tell (GSeekable *seekable)
88 {
89   GSeekableIface *iface;
90
91   g_return_val_if_fail (G_IS_SEEKABLE (seekable), 0);
92
93   iface = G_SEEKABLE_GET_IFACE (seekable);
94
95   return (* iface->tell) (seekable);
96 }
97
98 /**
99  * g_seekable_can_seek:
100  * @seekable: a #GSeekable.
101  * 
102  * Tests if the stream supports the #GSeekableIface.
103  * 
104  * Returns: %TRUE if @seekable can be seeked. %FALSE otherwise.
105  **/
106 gboolean
107 g_seekable_can_seek (GSeekable *seekable)
108 {
109   GSeekableIface *iface;
110   
111   g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
112
113   iface = G_SEEKABLE_GET_IFACE (seekable);
114
115   return (* iface->can_seek) (seekable);
116 }
117
118 /**
119  * g_seekable_seek:
120  * @seekable: a #GSeekable.
121  * @offset: a #goffset.
122  * @type: a #GSeekType.
123  * @cancellable: optional #GCancellable object, %NULL to ignore. 
124  * @error: a #GError location to store the error occuring, or %NULL to 
125  * ignore.
126  * 
127  * Seeks in the stream by the given @offset, modified by @type.
128  *
129  * If @cancellable is not %NULL, then the operation can be cancelled by
130  * triggering the cancellable object from another thread. If the operation
131  * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 
132  * 
133  * Returns: %TRUE if successful. If an error
134  *     has occured, this function will return %FALSE and set @error
135  *     appropriately if present.
136  **/
137 gboolean
138 g_seekable_seek (GSeekable     *seekable,
139                  goffset        offset,
140                  GSeekType      type,
141                  GCancellable  *cancellable,
142                  GError       **error)
143 {
144   GSeekableIface *iface;
145   
146   g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
147
148   iface = G_SEEKABLE_GET_IFACE (seekable);
149
150   return (* iface->seek) (seekable, offset, type, cancellable, error);
151 }
152
153 /**
154  * g_seekable_can_truncate:
155  * @seekable: a #GSeekable.
156  * 
157  * Tests if the stream can be truncated.
158  * 
159  * Returns: %TRUE if the stream can be truncated, %FALSE otherwise.
160  **/
161 gboolean
162 g_seekable_can_truncate (GSeekable *seekable)
163 {
164   GSeekableIface *iface;
165   
166   g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
167
168   iface = G_SEEKABLE_GET_IFACE (seekable);
169
170   return (* iface->can_truncate) (seekable);
171 }
172
173 /**
174  * g_seekable_truncate:
175  * @seekable: a #GSeekable.
176  * @offset: a #goffset.
177  * @cancellable: optional #GCancellable object, %NULL to ignore. 
178  * @error: a #GError location to store the error occuring, or %NULL to 
179  * ignore.
180  * 
181  * Truncates a stream with a given #offset. 
182  * 
183  * If @cancellable is not %NULL, then the operation can be cancelled by
184  * triggering the cancellable object from another thread. If the operation
185  * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
186  * operation was partially finished when the operation was cancelled the
187  * partial result will be returned, without an error.
188  * 
189  * Returns: %TRUE if successful. If an error
190  *     has occured, this function will return %FALSE and set @error
191  *     appropriately if present. 
192  **/
193 gboolean
194 g_seekable_truncate (GSeekable     *seekable,
195                      goffset        offset,
196                      GCancellable  *cancellable,
197                      GError       **error)
198 {
199   GSeekableIface *iface;
200   
201   g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
202
203   iface = G_SEEKABLE_GET_IFACE (seekable);
204
205   return (* iface->truncate) (seekable, offset, cancellable, error);
206 }
207
208 #define __G_SEEKABLE_C__
209 #include "gioaliasdef.c"