annotate libaudacious/vfs_gnome.c @ 32:8aee6a5bcc70 trunk

[svn] Libmikmod.
author nenolod
date Tue, 25 Oct 2005 22:53:38 -0700
parents cb178e5ad177
children ae0af0523844
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* This program is free software; you can redistribute it and/or modify
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 * it under the terms of the GNU General Public Licensse as published by
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 * the Free Software Foundation; either version 2 of the License, or
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 * (at your option) any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 * This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 * GNU General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 * You should have received a copy of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 * along with this program; if not, write to the Free Software
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 #include "vfs.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 #include <libgnomevfs/gnome-vfs.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 struct _VFSFile
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 GnomeVFSHandle *handle;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27 static void mode_to_gnome_vfs(const gchar * mode,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 GnomeVFSOpenMode * g_mode,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 gboolean * truncate,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 gboolean * append);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 vfs_init(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 if (!gnome_vfs_init())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 g_atexit(gnome_vfs_shutdown);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 VFSFile *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 vfs_fopen(const gchar * path,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 const gchar * mode)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 VFSFile *file;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 GnomeVFSResult g_result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 GnomeVFSOpenMode g_mode;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 gboolean truncate, append;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 file = g_new(VFSFile, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 mode_to_gnome_vfs(mode, &g_mode, &truncate, &append);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 if (!truncate) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 g_result = gnome_vfs_open(&(file->handle), path, g_mode);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 if (append && g_result == GNOME_VFS_ERROR_NOT_FOUND) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 g_result = gnome_vfs_create(&(file->handle),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 path, g_mode, TRUE,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 S_IRUSR | S_IWUSR |
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 S_IRGRP | S_IWGRP |
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 S_IROTH | S_IWOTH);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 if (append && g_result == GNOME_VFS_OK) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 g_result = gnome_vfs_seek(file->handle, GNOME_VFS_SEEK_END, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 if (g_result != GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 gnome_vfs_close(file->handle);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 g_result = gnome_vfs_create(&(file->handle),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 path, g_mode, FALSE,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 S_IRUSR | S_IWUSR |
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 if (g_result != GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 file->handle = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 if (file->handle == NULL) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 g_free(file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 file = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 return file;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 vfs_fclose(VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 gint ret = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 if (file->handle) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 if (gnome_vfs_close(file->handle) != GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 ret = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 g_free(file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 return ret;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 size_t
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 vfs_fread(gpointer ptr,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 size_t size,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 size_t nmemb,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 GnomeVFSFileSize bytes_read;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 result = gnome_vfs_read(file->handle, ptr, size * nmemb, &bytes_read);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 if (result == GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 return bytes_read;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 if (result == GNOME_VFS_ERROR_EOF)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 return 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 size_t
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 vfs_fwrite(gconstpointer ptr,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 size_t size,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 size_t nmemb,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 GnomeVFSFileSize bytes_written;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 result = gnome_vfs_write(file->handle, ptr, size * nmemb, &bytes_written);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 if (result == GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 return bytes_written;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 vfs_fseek(VFSFile * file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 glong offset,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 gint whence)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 GnomeVFSSeekPosition g_whence;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 switch (whence) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 case SEEK_SET:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 g_whence = GNOME_VFS_SEEK_START;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 case SEEK_CUR:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 g_whence = GNOME_VFS_SEEK_CURRENT;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 case SEEK_END:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 g_whence = GNOME_VFS_SEEK_END;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 g_warning("vfs_fseek: invalid whence value");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 result = gnome_vfs_seek(file->handle, g_whence, offset);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 if (result == GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 return 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 vfs_rewind(VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 vfs_fseek(file, 0L, SEEK_SET);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 glong
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 vfs_ftell(VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 GnomeVFSFileSize position;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 result = gnome_vfs_tell(file->handle, &position);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 if (result == GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 return position;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 vfs_file_test(const gchar * path,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 GFileTest test)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 GnomeVFSFileInfo info;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196 GFileTest file_test;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198 result = gnome_vfs_get_file_info(path, &info,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 if (test == G_FILE_TEST_EXISTS)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 return (result == GNOME_VFS_OK) ? TRUE : FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203 else if (test == G_FILE_TEST_IS_EXECUTABLE)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204 return (info.permissions & GNOME_VFS_PERM_ACCESS_EXECUTABLE)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 ? TRUE : FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207 switch (info.type) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208 case GNOME_VFS_FILE_TYPE_REGULAR:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209 file_test = G_FILE_TEST_IS_REGULAR;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211 case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212 file_test = G_FILE_TEST_IS_SYMLINK;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214 case GNOME_VFS_FILE_TYPE_DIRECTORY:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215 file_test = G_FILE_TEST_IS_DIR;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220 if (test == file_test)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227 vfs_is_writeable(const gchar * path)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 GnomeVFSFileInfo info;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 if (gnome_vfs_get_file_info(path, &info, GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 != GNOME_VFS_OK) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 return (info.permissions & GNOME_VFS_PERM_ACCESS_WRITABLE ? TRUE : FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240 vfs_truncate(VFSFile * file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 glong length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 result = gnome_vfs_truncate_handle(file->handle, (GnomeVFSFileSize) length);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247 if (result == GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248 return 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 static gchar *strdup_exclude_chars(const gchar * s,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254 const gchar * c);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257 mode_to_gnome_vfs(const gchar * mode,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258 GnomeVFSOpenMode * g_mode,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 gboolean * truncate,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 gboolean * append)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262 gchar *s;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264 *g_mode = GNOME_VFS_OPEN_RANDOM;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 *truncate = *append = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267 s = strdup_exclude_chars(mode, "bt");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268 switch (s[0]) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 case 'r':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 *g_mode |= GNOME_VFS_OPEN_READ;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272 if (s[1] == '+')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273 *g_mode |= GNOME_VFS_OPEN_WRITE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276 case 'w':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277 case 'a':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278 *g_mode |= GNOME_VFS_OPEN_WRITE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280 if (s[0] == 'w')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281 *truncate = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283 *append = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285 if (s[1] == '+')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286 *g_mode |= GNOME_VFS_OPEN_READ;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290 g_warning("mode_to_gnome_vfs: unhandled mode character");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292 g_free(s);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295 static gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296 strdup_exclude_chars(const gchar * s,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 const gchar * c)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 gint i, j, k;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300 gint newlen = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301 gchar *newstr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 gboolean found;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 /* Calculate number of chars in new string */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305 for (i = 0; s[i] != '\0'; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306 found = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308 for (j = 0; j < strlen(c) && !found; j++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309 if (s[i] == c[j])
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310 found = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312 if (!found)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313 newlen++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316 newstr = g_malloc(newlen + 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
318 /* Copy valid chars to new string */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319 for (i = k = 0; s[i] != '\0'; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320 found = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322 for (j = 0; j < strlen(c) && !found; j++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 if (s[i] == c[j])
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324 found = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326 if (!found)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327 newstr[k++] = s[i];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 newstr[k] = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 return newstr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333 }