annotate audacious/vfs.c @ 2159:35bdfcd17ba7 trunk

[svn] - change the cleanup order in mainwin_quit_cb() to avoid freeze on quit. - replace deprecated g_main_iteration() with g_main_context_iteration().
author yaz
date Mon, 18 Dec 2006 06:53:52 -0800
parents 12f8a35f86f5
children 329fb2453c87
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
1 /* Audacious
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
2 * Copyright (c) 2006 William Pitcock
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
3 *
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
4 * This program is free software; you can redistribute it and/or modify
1460
411b4aaf928b [svn] fine
nemo
parents: 1459
diff changeset
5 * it under the terms of the GNU General Public License as published by
2105
f18a5b617c34 [svn] - move to GPLv2-only. Based on my interpretation of the license, we are
nenolod
parents: 2071
diff changeset
6 * the Free Software Foundation; under version 2 of the License.
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 * GNU General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 * You should have received a copy of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 * along with this program; if not, write to the Free Software
1459
705d4c089fce [svn] Fix postal code.
chainsaw
parents: 1458
diff changeset
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 #include "vfs.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 #include <stdio.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 #include <unistd.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 #include <sys/stat.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 #include <sys/types.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24
2147
12f8a35f86f5 [svn] - fix
nenolod
parents: 2146
diff changeset
25 #include "libaudacious/urldecode.h"
2071
b9c6f1305c99 [svn] - move urldecode to libaudacious
nenolod
parents: 2060
diff changeset
26
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
27 static GList *vfs_transports = NULL;
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
28
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
29 #ifdef VFS_DEBUG
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
30 # define DBG(x, args...) g_print(x, ## args);
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
31 #else
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
32 # define DBG(x, args...)
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
33 #endif
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
34
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
35 /**
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
36 * vfs_register_transport:
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
37 * @vtable: The #VFSConstructor vtable to register.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
38 *
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
39 * Registers a #VFSConstructor vtable with the VFS system.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
40 *
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
41 * Return value: TRUE on success, FALSE on failure.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
42 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 gboolean
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
44 vfs_register_transport(VFSConstructor *vtable)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 {
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
46 vfs_transports = g_list_append(vfs_transports, vtable);
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
47
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
51 /**
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
52 * vfs_fopen:
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
53 * @path: The path or URI to open.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
54 * @mode: The preferred access privileges (not guaranteed).
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
55 *
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
56 * Opens a stream from a VFS transport using a #VFSConstructor.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
57 *
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
58 * Return value: On success, a #VFSFile object representing the stream.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
59 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 VFSFile *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 vfs_fopen(const gchar * path,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 const gchar * mode)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 VFSFile *file;
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
65 gchar **vec;
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
66 VFSConstructor *vtable = NULL;
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
67 GList *node;
2071
b9c6f1305c99 [svn] - move urldecode to libaudacious
nenolod
parents: 2060
diff changeset
68 gchar *decpath;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69
550
adee87ebe853 [svn] Sanity checking inside vfs_() functions.
nenolod
parents: 0
diff changeset
70 if (!path || !mode)
adee87ebe853 [svn] Sanity checking inside vfs_() functions.
nenolod
parents: 0
diff changeset
71 return NULL;
adee87ebe853 [svn] Sanity checking inside vfs_() functions.
nenolod
parents: 0
diff changeset
72
2071
b9c6f1305c99 [svn] - move urldecode to libaudacious
nenolod
parents: 2060
diff changeset
73 decpath = xmms_urldecode_plain(path);
b9c6f1305c99 [svn] - move urldecode to libaudacious
nenolod
parents: 2060
diff changeset
74
b9c6f1305c99 [svn] - move urldecode to libaudacious
nenolod
parents: 2060
diff changeset
75 vec = g_strsplit(decpath, "://", 2);
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
76
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
77 /* special case: no transport specified, look for the "/" transport */
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
78 if (vec[1] == NULL)
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
79 {
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
80 for (node = vfs_transports; node != NULL; node = g_list_next(node))
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
81 {
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
82 vtable = (VFSConstructor *) node->data;
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
83
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
84 if (*vtable->uri_id == '/')
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
85 break;
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
86 }
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
87 }
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
88 else
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
89 {
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
90 for (node = vfs_transports; node != NULL; node = g_list_next(node))
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
91 {
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
92 vtable = (VFSConstructor *) node->data;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
94 if (!g_strcasecmp(vec[0], vtable->uri_id))
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
95 break;
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
96 }
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
97 }
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
98
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
99 /* no transport vtable has been registered, bail. */
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
100 if (vtable == NULL)
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
101 {
2031
ebce0d5efac1 [svn] - don't leak the split URI vector after doing the vtable lookup
nenolod
parents: 1999
diff changeset
102 g_strfreev(vec);
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
103 return NULL;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
106 file = vtable->vfs_fopen_impl(vec[1] ? vec[1] : vec[0], mode);
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
107
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
108 if (file == NULL)
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
109 {
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
110 g_strfreev(vec);
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
111 return NULL;
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
112 }
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
113
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
114 file->uri = g_strdup(path);
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
115 file->base = vtable;
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
116
2031
ebce0d5efac1 [svn] - don't leak the split URI vector after doing the vtable lookup
nenolod
parents: 1999
diff changeset
117 g_strfreev(vec);
2071
b9c6f1305c99 [svn] - move urldecode to libaudacious
nenolod
parents: 2060
diff changeset
118 g_free(decpath);
2031
ebce0d5efac1 [svn] - don't leak the split URI vector after doing the vtable lookup
nenolod
parents: 1999
diff changeset
119
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 return file;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
123 /**
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
124 * vfs_fclose:
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
125 * @file: A #VFSFile object to destroy.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
126 *
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
127 * Closes a VFS stream and destroys a #VFSFile object.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
128 *
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
129 * Return value: -1 on failure, 0 on success.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
130 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 vfs_fclose(VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 gint ret = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
136 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
137 return -1;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
138
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
139 if (file->base->vfs_fclose_impl(file) != 0)
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
140 ret = -1;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141
1999
dcea7c329ad6 [svn] - don't memory leak the uri
nenolod
parents: 1998
diff changeset
142 if (file->uri != NULL)
dcea7c329ad6 [svn] - don't memory leak the uri
nenolod
parents: 1998
diff changeset
143 g_free(file->uri);
dcea7c329ad6 [svn] - don't memory leak the uri
nenolod
parents: 1998
diff changeset
144
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 g_free(file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 return ret;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
150 /**
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
151 * vfs_fread:
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
152 * @ptr: A pointer to the destination buffer.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
153 * @size: The size of each element to read.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
154 * @nmemb: The number of elements to read.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
155 * @file: #VFSFile object that represents the VFS stream.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
156 *
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
157 * Reads from a VFS stream.
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
158 *
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
159 * Return value: The amount of elements succesfully read.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
160 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 size_t
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 vfs_fread(gpointer ptr,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 size_t size,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 size_t nmemb,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
167 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
168 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
169
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
170 return file->base->vfs_fread_impl(ptr, size, nmemb, file);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
173 /**
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
174 * vfs_fwrite:
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
175 * @ptr: A const pointer to the source buffer.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
176 * @size: The size of each element to write.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
177 * @nmemb: The number of elements to write.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
178 * @file: #VFSFile object that represents the VFS stream.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
179 *
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
180 * Writes to a VFS stream.
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
181 *
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
182 * Return value: The amount of elements succesfully written.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
183 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 size_t
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 vfs_fwrite(gconstpointer ptr,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 size_t size,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 size_t nmemb,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
190 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
191 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
192
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
193 return file->base->vfs_fwrite_impl(ptr, size, nmemb, file);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
196 /**
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
197 * vfs_getc:
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
198 * @stream: #VFSFile object that represents the VFS stream.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
199 *
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
200 * Reads a character from a VFS stream.
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
201 *
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
202 * Return value: On success, a character. Otherwise, -1.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
203 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204 gint
1683
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
205 vfs_getc(VFSFile *stream)
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
206 {
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
207 if (stream == NULL)
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
208 return -1;
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
209
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
210 return stream->base->vfs_getc_impl(stream);
1683
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
211 }
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
212
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
213 /**
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
214 * vfs_ungetc:
2060
53a3d5db6b58 [svn] - finish documenting the libaudacious API
nenolod
parents: 2059
diff changeset
215 * @c: The character to push back.
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
216 * @stream: #VFSFile object that represents the VFS stream.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
217 *
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
218 * Pushes a character back to the VFS stream.
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
219 *
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
220 * Return value: On success, 0. Otherwise, -1.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
221 **/
1683
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
222 gint
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
223 vfs_ungetc(gint c, VFSFile *stream)
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
224 {
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
225 if (stream == NULL)
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
226 return -1;
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
227
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
228 return stream->base->vfs_ungetc_impl(c, stream);
1683
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
229 }
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
230
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
231 /**
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
232 * vfs_fseek:
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
233 * @file: #VFSFile object that represents the VFS stream.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
234 * @offset: The offset to seek to.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
235 * @whence: Whether or not the seek is absolute or not.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
236 *
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
237 * Seeks through a VFS stream.
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
238 *
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
239 * Return value: On success, 1. Otherwise, 0.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
240 **/
1683
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
241 gint
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 vfs_fseek(VFSFile * file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 glong offset,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 gint whence)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
246 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
247 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
248
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
249 return file->base->vfs_fseek_impl(file, offset, whence);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
252 /**
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
253 * vfs_rewind:
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
254 * @file: #VFSFile object that represents the VFS stream.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
255 *
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
256 * Rewinds a VFS stream.
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
257 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 vfs_rewind(VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
261 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
262 return;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
263
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
264 file->base->vfs_rewind_impl(file);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
267 /**
2059
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 2034
diff changeset
268 * vfs_ftell:
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
269 * @file: #VFSFile object that represents the VFS stream.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
270 *
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
271 * Returns the current position in the VFS stream's buffer.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
272 *
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
273 * Return value: On success, the current position. Otherwise, -1.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
274 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275 glong
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276 vfs_ftell(VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
278 if (file == NULL)
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
279 return -1;
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
280
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
281 return file->base->vfs_ftell_impl(file);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
284 /**
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
285 * vfs_feof:
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
286 * @file: #VFSFile object that represents the VFS stream.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
287 *
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
288 * Returns whether or not the VFS stream has reached EOF.
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
289 *
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
290 * Return value: On success, whether or not the VFS stream is at EOF. Otherwise, FALSE.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
291 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292 gboolean
811
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
293 vfs_feof(VFSFile * file)
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
294 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
295 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
296 return FALSE;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
297
1997
93c59698f5fd [svn] - NewVFS lives ;)
nenolod
parents: 1976
diff changeset
298 return (gboolean) file->base->vfs_feof_impl(file);
811
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
299 }
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
300
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
301 /**
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
302 * vfs_truncate:
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
303 * @file: #VFSFile object that represents the VFS stream.
2059
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 2034
diff changeset
304 * @length: The length to truncate at.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
305 *
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
306 * Truncates a VFS stream to a certain size.
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
307 *
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
308 * Return value: On success, 0. Otherwise, -1.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
309 **/
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
310 gint
2059
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 2034
diff changeset
311 vfs_truncate(VFSFile * file, glong length)
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
312 {
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
313 if (file == NULL)
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
314 return -1;
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
315
2059
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 2034
diff changeset
316 return file->base->vfs_truncate_impl(file, length);
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
317 }
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
318
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
319 /**
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
320 * vfs_file_test:
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
321 * @path: A path to test.
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
322 * @test: A GFileTest to run.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
323 *
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
324 * Wrapper for g_file_test().
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
325 *
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
326 * Return value: The result of g_file_test().
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
327 **/
811
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
328 gboolean
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 vfs_file_test(const gchar * path, GFileTest test)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331 return g_file_test(path, test);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
334 /**
2059
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 2034
diff changeset
335 * vfs_is_writeable:
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
336 * @path: A path to test.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
337 *
2059
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 2034
diff changeset
338 * Tests if a file is writeable.
2032
7aed5cf10141 [svn] - document the VFS layer.
nenolod
parents: 2031
diff changeset
339 *
2059
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 2034
diff changeset
340 * Return value: TRUE if the file is writeable, otherwise FALSE.
2034
c43fb0845b71 [svn] - update VFS documentation
nenolod
parents: 2032
diff changeset
341 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343 vfs_is_writeable(const gchar * path)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345 struct stat info;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
346
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
347 if (stat(path, &info) == -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
348 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
349
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
350 return (info.st_mode & S_IWUSR);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
351 }