annotate src/audacious/vfs.c @ 2597:4ce36bfe9cf7 trunk

[svn] - correct a keyboard shortcut collision. closes #824.
author nenolod
date Thu, 01 Mar 2007 08:22:32 -0800
parents 48288757d7c7
children 0ad10a95ed10
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
1 /* Audacious
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
2 * Copyright (c) 2006-2007 William Pitcock
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
3 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
6 * the Free Software Foundation; under version 2 of the License.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
7 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
11 * GNU General Public License for more details.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
12 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
13 * You should have received a copy of the GNU General Public License
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
14 * along with this program; if not, write to the Free Software
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
16 */
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
17
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
18 #include "vfs.h"
2579
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
19 #include "strings.h"
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
20 #include <stdio.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
21
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
22 #include <unistd.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
23 #include <sys/stat.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
24 #include <sys/types.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
25
2336
b332cdd2ea43 [svn] - warning fixes
nenolod
parents: 2335
diff changeset
26 #include <string.h>
b332cdd2ea43 [svn] - warning fixes
nenolod
parents: 2335
diff changeset
27
2416
0fd7f4f969ad [svn] integrated urldecode.* from libaudacious into audacious directory, made separate ui_fileopener.*
mf0102
parents: 2381
diff changeset
28 #include "urldecode.h"
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
29
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
30 static GList *vfs_transports = NULL;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
31
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
32 #ifdef VFS_DEBUG
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
33 # define DBG(x, args...) g_print(x, ## args);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
34 #else
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
35 # define DBG(x, args...)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
36 #endif
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
37
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
38 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
39 * vfs_register_transport:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
40 * @vtable: The #VFSConstructor vtable to register.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
41 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
42 * Registers a #VFSConstructor vtable with the VFS system.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
43 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
44 * Return value: TRUE on success, FALSE on failure.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
45 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
46 gboolean
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
47 vfs_register_transport(VFSConstructor *vtable)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
48 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
49 vfs_transports = g_list_append(vfs_transports, vtable);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
50
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
51 return TRUE;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
52 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
53
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
54 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
55 * vfs_fopen:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
56 * @path: The path or URI to open.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
57 * @mode: The preferred access privileges (not guaranteed).
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
58 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
59 * Opens a stream from a VFS transport using a #VFSConstructor.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
60 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
61 * Return value: On success, a #VFSFile object representing the stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
62 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
63 VFSFile *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
64 vfs_fopen(const gchar * path,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
65 const gchar * mode)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
66 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
67 VFSFile *file;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
68 VFSConstructor *vtable = NULL;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
69 GList *node;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
70 gchar *decpath;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
71
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
72 if (!path || !mode)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
73 return NULL;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
74
2381
d49913587458 [svn] - changes to the nature of URI handling in the VFS subsystem, will be
nenolod
parents: 2376
diff changeset
75 decpath = g_strdup(path);
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
76
2335
e80c9dfc93aa [svn] - g_strsplit() wraps strsplit(3), and thus has different results on
nenolod
parents: 2313
diff changeset
77 for (node = vfs_transports; node != NULL; node = g_list_next(node))
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
78 {
2534
c3d5ac206052 [svn] - fix a typo
nenolod
parents: 2533
diff changeset
79 VFSConstructor *vtptr = (VFSConstructor *) node->data;
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
80
2533
ab335d4391df [svn] - don't return a bogus vtable for an unregistered URI scheme
nenolod
parents: 2416
diff changeset
81 if (!strncasecmp(decpath, vtptr->uri_id, strlen(vtptr->uri_id)))
ab335d4391df [svn] - don't return a bogus vtable for an unregistered URI scheme
nenolod
parents: 2416
diff changeset
82 {
ab335d4391df [svn] - don't return a bogus vtable for an unregistered URI scheme
nenolod
parents: 2416
diff changeset
83 vtable = vtptr;
2335
e80c9dfc93aa [svn] - g_strsplit() wraps strsplit(3), and thus has different results on
nenolod
parents: 2313
diff changeset
84 break;
2533
ab335d4391df [svn] - don't return a bogus vtable for an unregistered URI scheme
nenolod
parents: 2416
diff changeset
85 }
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
86 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
87
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
88 /* no transport vtable has been registered, bail. */
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
89 if (vtable == NULL)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
90 return NULL;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
91
2381
d49913587458 [svn] - changes to the nature of URI handling in the VFS subsystem, will be
nenolod
parents: 2376
diff changeset
92 file = vtable->vfs_fopen_impl(decpath, mode);
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
93
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
94 if (file == NULL)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
95 return NULL;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
96
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
97 file->uri = g_strdup(path);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
98 file->base = vtable;
2562
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
99 file->ref = 1;
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
100
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
101 g_free(decpath);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
102
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
103 return file;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
104 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
105
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
106 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
107 * vfs_fclose:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
108 * @file: A #VFSFile object to destroy.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
109 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
110 * Closes a VFS stream and destroys a #VFSFile object.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
111 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
112 * Return value: -1 on failure, 0 on success.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
113 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
114 gint
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
115 vfs_fclose(VFSFile * file)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
116 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
117 gint ret = 0;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
118
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
119 if (file == NULL)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
120 return -1;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
121
2562
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
122 if (--file->ref > 0)
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
123 return -1;
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
124
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
125 if (file->base->vfs_fclose_impl(file) != 0)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
126 ret = -1;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
127
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
128 if (file->uri != NULL)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
129 g_free(file->uri);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
130
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
131 g_free(file);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
132
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
133 return ret;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
134 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
135
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
136 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
137 * vfs_fread:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
138 * @ptr: A pointer to the destination buffer.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
139 * @size: The size of each element to read.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
140 * @nmemb: The number of elements to read.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
141 * @file: #VFSFile object that represents the VFS stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
142 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
143 * Reads from a VFS stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
144 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
145 * Return value: The amount of elements succesfully read.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
146 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
147 size_t
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
148 vfs_fread(gpointer ptr,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
149 size_t size,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
150 size_t nmemb,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
151 VFSFile * file)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
152 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
153 if (file == NULL)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
154 return 0;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
155
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
156 return file->base->vfs_fread_impl(ptr, size, nmemb, file);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
157 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
158
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
159 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
160 * vfs_fwrite:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
161 * @ptr: A const pointer to the source buffer.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
162 * @size: The size of each element to write.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
163 * @nmemb: The number of elements to write.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
164 * @file: #VFSFile object that represents the VFS stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
165 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
166 * Writes to a VFS stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
167 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
168 * Return value: The amount of elements succesfully written.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
169 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
170 size_t
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
171 vfs_fwrite(gconstpointer ptr,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
172 size_t size,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
173 size_t nmemb,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
174 VFSFile * file)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
175 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
176 if (file == NULL)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
177 return 0;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
178
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
179 return file->base->vfs_fwrite_impl(ptr, size, nmemb, file);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
180 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
181
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
182 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
183 * vfs_getc:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
184 * @stream: #VFSFile object that represents the VFS stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
185 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
186 * Reads a character from a VFS stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
187 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
188 * Return value: On success, a character. Otherwise, -1.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
189 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
190 gint
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
191 vfs_getc(VFSFile *stream)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
192 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
193 if (stream == NULL)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
194 return -1;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
195
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
196 return stream->base->vfs_getc_impl(stream);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
197 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
198
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
199 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
200 * vfs_ungetc:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
201 * @c: The character to push back.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
202 * @stream: #VFSFile object that represents the VFS stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
203 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
204 * Pushes a character back to the VFS stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
205 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
206 * Return value: On success, 0. Otherwise, -1.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
207 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
208 gint
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
209 vfs_ungetc(gint c, VFSFile *stream)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
210 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
211 if (stream == NULL)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
212 return -1;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
213
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
214 return stream->base->vfs_ungetc_impl(c, stream);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
215 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
216
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
217 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
218 * vfs_fseek:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
219 * @file: #VFSFile object that represents the VFS stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
220 * @offset: The offset to seek to.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
221 * @whence: Whether or not the seek is absolute or not.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
222 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
223 * Seeks through a VFS stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
224 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
225 * Return value: On success, 1. Otherwise, 0.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
226 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
227 gint
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
228 vfs_fseek(VFSFile * file,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
229 glong offset,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
230 gint whence)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
231 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
232 if (file == NULL)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
233 return 0;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
234
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
235 return file->base->vfs_fseek_impl(file, offset, whence);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
236 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
237
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
238 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
239 * vfs_rewind:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
240 * @file: #VFSFile object that represents the VFS stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
241 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
242 * Rewinds a VFS stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
243 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
244 void
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
245 vfs_rewind(VFSFile * file)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
246 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
247 if (file == NULL)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
248 return;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
249
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
250 file->base->vfs_rewind_impl(file);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
251 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
252
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
253 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
254 * vfs_ftell:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
255 * @file: #VFSFile object that represents the VFS stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
256 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
257 * Returns the current position in the VFS stream's buffer.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
258 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
259 * Return value: On success, the current position. Otherwise, -1.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
260 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
261 glong
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
262 vfs_ftell(VFSFile * file)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
263 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
264 if (file == NULL)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
265 return -1;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
266
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
267 return file->base->vfs_ftell_impl(file);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
268 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
269
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
270 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
271 * vfs_feof:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
272 * @file: #VFSFile object that represents the VFS stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
273 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
274 * Returns whether or not the VFS stream has reached EOF.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
275 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
276 * Return value: On success, whether or not the VFS stream is at EOF. Otherwise, FALSE.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
277 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
278 gboolean
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
279 vfs_feof(VFSFile * file)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
280 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
281 if (file == NULL)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
282 return FALSE;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
283
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
284 return (gboolean) file->base->vfs_feof_impl(file);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
285 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
286
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
287 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
288 * vfs_truncate:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
289 * @file: #VFSFile object that represents the VFS stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
290 * @length: The length to truncate at.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
291 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
292 * Truncates a VFS stream to a certain size.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
293 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
294 * Return value: On success, 0. Otherwise, -1.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
295 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
296 gint
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
297 vfs_truncate(VFSFile * file, glong length)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
298 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
299 if (file == NULL)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
300 return -1;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
301
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
302 return file->base->vfs_truncate_impl(file, length);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
303 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
304
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
305 /**
2376
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
306 * vfs_get_metadata:
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
307 * @file: #VFSFile object that represents the VFS stream.
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
308 * @field: The string constant field name to get.
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
309 *
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
310 * Returns metadata about the stream.
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
311 *
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
312 * Return value: On success, a copy of the value of the
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
313 * field. Otherwise, NULL.
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
314 **/
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
315 gchar *
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
316 vfs_get_metadata(VFSFile * file, const gchar * field)
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
317 {
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
318 if (file == NULL)
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
319 return NULL;
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
320
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
321 if (file->base->vfs_get_metadata_impl)
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
322 return file->base->vfs_get_metadata_impl(file, field);
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
323 return NULL;
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
324 }
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
325
2579
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
326 static gchar *
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
327 _vfs_urldecode_basic_path(const gchar * encoded_path)
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
328 {
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
329 const gchar *cur, *ext;
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
330 gchar *path, *tmp;
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
331 gint realchar;
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
332
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
333 if (!encoded_path)
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
334 return NULL;
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
335
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
336 if (!str_has_prefix_nocase(encoded_path, "file:"))
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
337 return NULL;
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
338
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
339 cur = encoded_path + 5;
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
340
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
341 if (str_has_prefix_nocase(cur, "//localhost"))
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
342 cur += 11;
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
343
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
344 if (*cur == '/')
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
345 while (cur[1] == '/')
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
346 cur++;
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
347
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
348 tmp = g_malloc0(strlen(cur) + 1);
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
349
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
350 while ((ext = strchr(cur, '%')) != NULL) {
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
351 strncat(tmp, cur, ext - cur);
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
352 ext++;
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
353 cur = ext + 2;
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
354 if (!sscanf(ext, "%2x", &realchar)) {
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
355 /* Assume it is a literal '%'. Several file
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
356 * managers send unencoded file: urls on drag
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
357 * and drop. */
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
358 realchar = '%';
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
359 cur -= 2;
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
360 }
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
361 tmp[strlen(tmp)] = realchar;
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
362 }
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
363
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
364 path = g_strconcat(tmp, cur, NULL);
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
365 g_free(tmp);
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
366 return path;
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
367 }
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
368
2376
e1513290ee3c [svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents: 2370
diff changeset
369 /**
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
370 * vfs_file_test:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
371 * @path: A path to test.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
372 * @test: A GFileTest to run.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
373 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
374 * Wrapper for g_file_test().
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
375 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
376 * Return value: The result of g_file_test().
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
377 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
378 gboolean
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
379 vfs_file_test(const gchar * path, GFileTest test)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
380 {
2575
9713b5a67cba [svn] - make directory drag-and-drop work again.
nenolod
parents: 2562
diff changeset
381 gchar *path2;
9713b5a67cba [svn] - make directory drag-and-drop work again.
nenolod
parents: 2562
diff changeset
382 gboolean ret;
9713b5a67cba [svn] - make directory drag-and-drop work again.
nenolod
parents: 2562
diff changeset
383
2579
364714f2d555 [svn] - urldecode playlist paths
nenolod
parents: 2575
diff changeset
384 path2 = _vfs_urldecode_basic_path(path);
2575
9713b5a67cba [svn] - make directory drag-and-drop work again.
nenolod
parents: 2562
diff changeset
385
2580
48288757d7c7 [svn] - fix a regression introduced by the DnD fix.
nenolod
parents: 2579
diff changeset
386 if (path2 == NULL)
48288757d7c7 [svn] - fix a regression introduced by the DnD fix.
nenolod
parents: 2579
diff changeset
387 path2 = g_strdup(path);
48288757d7c7 [svn] - fix a regression introduced by the DnD fix.
nenolod
parents: 2579
diff changeset
388
2575
9713b5a67cba [svn] - make directory drag-and-drop work again.
nenolod
parents: 2562
diff changeset
389 ret = g_file_test(path2, test);
9713b5a67cba [svn] - make directory drag-and-drop work again.
nenolod
parents: 2562
diff changeset
390
9713b5a67cba [svn] - make directory drag-and-drop work again.
nenolod
parents: 2562
diff changeset
391 g_free(path2);
9713b5a67cba [svn] - make directory drag-and-drop work again.
nenolod
parents: 2562
diff changeset
392
9713b5a67cba [svn] - make directory drag-and-drop work again.
nenolod
parents: 2562
diff changeset
393 return ret;
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
394 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
395
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
396 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
397 * vfs_is_writeable:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
398 * @path: A path to test.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
399 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
400 * Tests if a file is writeable.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
401 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
402 * Return value: TRUE if the file is writeable, otherwise FALSE.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
403 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
404 gboolean
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
405 vfs_is_writeable(const gchar * path)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
406 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
407 struct stat info;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
408
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
409 if (stat(path, &info) == -1)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
410 return FALSE;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
411
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
412 return (info.st_mode & S_IWUSR);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
413 }
2562
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
414
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
415 /**
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
416 * vfs_dup:
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
417 * @in: The VFSFile handle to mark as duplicated.
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
418 *
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
419 * Increments the amount of references that are using this FD.
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
420 * References are removed by calling vfs_fclose on the handle returned
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
421 * from this function.
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
422 * If the amount of references reaches zero, then the file will be
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
423 * closed.
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
424 **/
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
425 VFSFile *
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
426 vfs_dup(VFSFile *in)
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
427 {
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
428 g_return_val_if_fail(in != NULL, NULL);
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
429
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
430 in->ref++;
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
431
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
432 return in;
07b990906823 [svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents: 2534
diff changeset
433 }