annotate src/gio/gio.c @ 3092:1e39f795348c

gio: make sure we return the number of bytes we pulled off the getc() stack. (This makes wavpack happy, but not libid3tag.)
author William Pitcock <nenolod@atheme.org>
date Thu, 30 Apr 2009 07:02:04 -0500
parents 2bd8895c9fe0
children cdf79f7b0d9e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1 /* Audacious
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2 * Copyright (c) 2009 William Pitcock
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
3 *
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
7 * (at your option) any later version.
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
8 *
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
12 * GNU General Public License for more details.
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
13 *
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
15 * along with this program; if not, write to the Free Software
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
17 */
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
18
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
19 #include "config.h"
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
20 #include <audacious/plugin.h>
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
21 #include <stdio.h>
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
22 #include <gio/gio.h>
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
23
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
24 #include <unistd.h>
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
25 #include <sys/stat.h>
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
26 #include <sys/types.h>
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
27
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
28 #include <string.h>
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
29
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
30 typedef struct {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
31 GFile *file;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
32 GFileInputStream *istream;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
33 GFileOutputStream *ostream;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
34 GSeekable *seekable;
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
35 GSList *stream_stack;
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
36 } VFSGIOHandle;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
37
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
38 VFSFile *
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
39 gio_aud_vfs_fopen_impl(const gchar *path, const gchar *mode)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
40 {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
41 VFSFile *file;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
42 VFSGIOHandle *handle;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
43 GError *error = NULL;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
44
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
45 if (path == NULL || mode == NULL)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
46 return NULL;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
47
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
48 handle = g_slice_new0(VFSGIOHandle);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
49 handle->file = g_file_new_for_uri(path);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
50
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
51 if (*mode == 'r')
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
52 {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
53 handle->istream = g_file_read(handle->file, NULL, &error);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
54 handle->seekable = G_SEEKABLE(handle->istream);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
55 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
56 else if (*mode == 'w')
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
57 {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
58 handle->ostream = g_file_replace(handle->file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
59 handle->seekable = G_SEEKABLE(handle->ostream);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
60 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
61 else
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
62 {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
63 g_warning("UNSUPPORTED ACCESS MODE: %s", mode);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
64 g_object_unref(handle->file);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
65 g_slice_free(VFSGIOHandle, handle);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
66 return NULL;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
67 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
68
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
69 if (handle->istream == NULL && handle->ostream == NULL)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
70 {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
71 g_warning("Could not open %s for reading or writing: %s", path, error->message);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
72 g_object_unref(handle->file);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
73 g_slice_free(VFSGIOHandle, handle);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
74 g_error_free(error);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
75 return NULL;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
76 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
77
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
78 file = g_new(VFSFile, 1);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
79 file->handle = handle;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
80
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
81 return file;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
82 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
83
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
84 gint
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
85 gio_aud_vfs_fclose_impl(VFSFile * file)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
86 {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
87 gint ret = 0;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
88
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
89 g_return_val_if_fail(file != NULL, -1);
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
90
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
91 if (file->handle)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
92 {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
93 VFSGIOHandle *handle = (VFSGIOHandle *) file->handle;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
94
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
95 g_object_unref(handle->file);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
96 g_slice_free(VFSGIOHandle, handle);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
97
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
98 file->handle = NULL;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
99 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
100
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
101 return ret;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
102 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
103
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
104 size_t
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
105 gio_aud_vfs_fread_impl(gpointer ptr,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
106 size_t size,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
107 size_t nmemb,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
108 VFSFile * file)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
109 {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
110 VFSGIOHandle *handle;
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
111 goffset count = 0;
3084
e02b6092f70e gio: handle ungetc() stack accesses larger than size (e.g. support size * nmemb as it should be)
William Pitcock <nenolod@atheme.org>
parents: 3083
diff changeset
112 gsize realsize = (size * nmemb);
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
113
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
114 g_return_val_if_fail(file != NULL, EOF);
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
115 g_return_val_if_fail(file->handle != NULL, EOF);
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
116
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
117 handle = (VFSGIOHandle *) file->handle;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
118
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
119 /* handle ungetc() *grumble* --nenolod */
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
120 if (handle->stream_stack != NULL)
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
121 {
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
122 guchar uc;
3084
e02b6092f70e gio: handle ungetc() stack accesses larger than size (e.g. support size * nmemb as it should be)
William Pitcock <nenolod@atheme.org>
parents: 3083
diff changeset
123 while ((count < realsize) && (handle->stream_stack != NULL))
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
124 {
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
125 uc = GPOINTER_TO_INT(handle->stream_stack->data);
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
126 handle->stream_stack = g_slist_delete_link(handle->stream_stack, handle->stream_stack);
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
127 memcpy(ptr + count, &uc, 1);
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
128 count++;
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
129 }
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
130 }
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
131
3092
1e39f795348c gio: make sure we return the number of bytes we pulled off the getc() stack.
William Pitcock <nenolod@atheme.org>
parents: 3091
diff changeset
132 return (g_input_stream_read(G_INPUT_STREAM(handle->istream), (ptr + count), (realsize - count), NULL, NULL) + count);
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
133 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
134
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
135 size_t
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
136 gio_aud_vfs_fwrite_impl(gconstpointer ptr,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
137 size_t size,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
138 size_t nmemb,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
139 VFSFile * file)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
140 {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
141 VFSGIOHandle *handle;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
142
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
143 g_return_val_if_fail(file != NULL, EOF);
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
144 g_return_val_if_fail(file->handle != NULL, EOF);
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
145
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
146 handle = (VFSGIOHandle *) file->handle;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
147
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
148 return g_output_stream_write(G_OUTPUT_STREAM(handle->ostream), ptr, size * nmemb, NULL, NULL);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
149 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
150
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
151 gint
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
152 gio_aud_vfs_getc_impl(VFSFile *file)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
153 {
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
154 guchar buf;
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
155 VFSGIOHandle *handle;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
156
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
157 g_return_val_if_fail(file != NULL, EOF);
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
158 g_return_val_if_fail(file->handle != NULL, EOF);
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
159
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
160 handle = (VFSGIOHandle *) file->handle;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
161
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
162 if (handle->stream_stack != NULL)
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
163 {
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
164 buf = GPOINTER_TO_INT(handle->stream_stack->data);
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
165 handle->stream_stack = g_slist_delete_link(handle->stream_stack, handle->stream_stack);
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
166 return buf;
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
167 }
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
168 else if (g_input_stream_read(G_INPUT_STREAM(handle->istream), &buf, 1, NULL, NULL) == -1)
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
169 return EOF;
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
170
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
171 return buf;
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
172 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
173
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
174 gint
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
175 gio_aud_vfs_ungetc_impl(gint c, VFSFile * file)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
176 {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
177 VFSGIOHandle *handle;
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
178
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
179 g_return_val_if_fail(file != NULL, EOF);
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
180 g_return_val_if_fail(file->handle != NULL, EOF);
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
181
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
182 handle = (VFSGIOHandle *) file->handle;
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
183 handle->stream_stack = g_slist_prepend(handle->stream_stack, GINT_TO_POINTER(c));
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
184 if (handle->stream_stack != NULL)
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
185 return c;
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
186
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
187 return EOF;
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
188 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
189
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
190 gint
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
191 gio_aud_vfs_fseek_impl(VFSFile * file,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
192 glong offset,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
193 gint whence)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
194 {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
195 VFSGIOHandle *handle;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
196 GSeekType seektype;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
197
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
198 g_return_val_if_fail(file != NULL, -1);
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
199 g_return_val_if_fail(file->handle != NULL, -1);
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
200
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
201 handle = (VFSGIOHandle *) file->handle;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
202
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
203 if (!g_seekable_can_seek(handle->seekable))
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
204 return -1;
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
205
3087
f333e6df5fa9 ungetc(): trash the stack of ungetc()'d chars if a seek is made
William Pitcock <nenolod@atheme.org>
parents: 3084
diff changeset
206 if (handle->stream_stack != NULL)
f333e6df5fa9 ungetc(): trash the stack of ungetc()'d chars if a seek is made
William Pitcock <nenolod@atheme.org>
parents: 3084
diff changeset
207 {
f333e6df5fa9 ungetc(): trash the stack of ungetc()'d chars if a seek is made
William Pitcock <nenolod@atheme.org>
parents: 3084
diff changeset
208 g_slist_free(handle->stream_stack);
f333e6df5fa9 ungetc(): trash the stack of ungetc()'d chars if a seek is made
William Pitcock <nenolod@atheme.org>
parents: 3084
diff changeset
209 handle->stream_stack = NULL;
f333e6df5fa9 ungetc(): trash the stack of ungetc()'d chars if a seek is made
William Pitcock <nenolod@atheme.org>
parents: 3084
diff changeset
210 }
f333e6df5fa9 ungetc(): trash the stack of ungetc()'d chars if a seek is made
William Pitcock <nenolod@atheme.org>
parents: 3084
diff changeset
211
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
212 switch (whence)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
213 {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
214 case SEEK_CUR:
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
215 seektype = G_SEEK_CUR;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
216 break;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
217 case SEEK_END:
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
218 seektype = G_SEEK_END;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
219 break;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
220 default:
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
221 seektype = G_SEEK_SET;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
222 break;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
223 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
224
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
225 return (g_seekable_seek(handle->seekable, offset, seektype, NULL, NULL) ? 0 : -1);
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
226 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
227
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
228 void
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
229 gio_aud_vfs_rewind_impl(VFSFile * file)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
230 {
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
231 g_return_if_fail(file != NULL);
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
232
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
233 file->base->vfs_fseek_impl(file, 0, SEEK_SET);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
234 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
235
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
236 glong
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
237 gio_aud_vfs_ftell_impl(VFSFile * file)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
238 {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
239 VFSGIOHandle *handle;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
240
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
241 g_return_val_if_fail(file != NULL, -1);
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
242 g_return_val_if_fail(file->handle != NULL, -1);
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
243
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
244 handle = (VFSGIOHandle *) file->handle;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
245
3091
2bd8895c9fe0 gio: if we ungetc(), then our position moves backwards by the number of ungetc()'d bytes.
William Pitcock <nenolod@atheme.org>
parents: 3087
diff changeset
246 return (glong) (g_seekable_tell(handle->seekable) - g_slist_length(handle->stream_stack));
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
247 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
248
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
249 gboolean
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
250 gio_aud_vfs_feof_impl(VFSFile * file)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
251 {
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
252 g_return_val_if_fail(file != NULL, TRUE);
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
253
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
254 return (file->base->vfs_ftell_impl(file) == file->base->vfs_fsize_impl(file));
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
255 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
256
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
257 gint
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
258 gio_aud_vfs_truncate_impl(VFSFile * file, glong size)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
259 {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
260 VFSGIOHandle *handle;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
261
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
262 g_return_val_if_fail(file != NULL, -1);
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
263
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
264 handle = (VFSGIOHandle *) file->handle;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
265
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
266 return g_seekable_truncate(handle->seekable, size, NULL, NULL);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
267 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
268
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
269 off_t
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
270 gio_aud_vfs_fsize_impl(VFSFile * file)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
271 {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
272 GFileInfo *info;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
273 VFSGIOHandle *handle;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
274 GError *error = NULL;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
275 goffset size;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
276
3082
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
277 g_return_val_if_fail(file != NULL, -1);
abb8604cb718 Implement getc()/ungetc(), and fix seeking.
William Pitcock <nenolod@atheme.org>
parents: 3081
diff changeset
278 g_return_val_if_fail(file->handle != NULL, -1);
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
279
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
280 handle = (VFSGIOHandle *) file->handle;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
281 info = g_file_query_info(handle->file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, &error);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
282
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
283 if (info == NULL)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
284 {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
285 g_warning("gio fsize(): error: %s", error->message);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
286 g_error_free(error);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
287 return -1;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
288 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
289
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
290 size = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_STANDARD_SIZE);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
291 g_object_unref(info);
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
292
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
293 return size;
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
294 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
295
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
296 VFSConstructor file_const = {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
297 .uri_id = "file://",
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
298 .vfs_fopen_impl = gio_aud_vfs_fopen_impl,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
299 .vfs_fclose_impl = gio_aud_vfs_fclose_impl,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
300 .vfs_fread_impl = gio_aud_vfs_fread_impl,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
301 .vfs_fwrite_impl = gio_aud_vfs_fwrite_impl,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
302 .vfs_getc_impl = gio_aud_vfs_getc_impl,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
303 .vfs_ungetc_impl = gio_aud_vfs_ungetc_impl,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
304 .vfs_fseek_impl = gio_aud_vfs_fseek_impl,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
305 .vfs_rewind_impl = gio_aud_vfs_rewind_impl,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
306 .vfs_ftell_impl = gio_aud_vfs_ftell_impl,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
307 .vfs_feof_impl = gio_aud_vfs_feof_impl,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
308 .vfs_truncate_impl = gio_aud_vfs_truncate_impl,
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
309 .vfs_fsize_impl = gio_aud_vfs_fsize_impl
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
310 };
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
311
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
312 static void init(void)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
313 {
3083
01d2f931aeeb gio: remove debug statement
William Pitcock <nenolod@atheme.org>
parents: 3082
diff changeset
314 aud_vfs_register_transport(&file_const);
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
315 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
316
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
317 static void cleanup(void)
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
318 {
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
319 #if 0
3083
01d2f931aeeb gio: remove debug statement
William Pitcock <nenolod@atheme.org>
parents: 3082
diff changeset
320 aud_vfs_unregister_transport(&file_const);
3081
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
321 #endif
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
322 }
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
323
4e3712e142b4 gio: merge experimental GIO plugin. not everything is implemented yet (getc/ungetc).
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
324 DECLARE_PLUGIN(gio, init, cleanup, NULL, NULL, NULL, NULL, NULL, NULL);