annotate libaudacious/vfs_gnome.c @ 160:faa50a5760ee trunk

[svn] Do not try to build LIRC when not enabled.
author chainsaw
date Sat, 12 Nov 2005 17:20:49 -0800
parents ae0af0523844
children adee87ebe853
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);
78
ae0af0523844 [svn] Call gnome_vfs_escape_path_string() before attempting to open the file.
msameer
parents: 0
diff changeset
54 gchar *escaped_file = gnome_vfs_escape_path_string(path);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 if (!truncate) {
78
ae0af0523844 [svn] Call gnome_vfs_escape_path_string() before attempting to open the file.
msameer
parents: 0
diff changeset
57 g_result = gnome_vfs_open(&(file->handle), escaped_file, g_mode);
0
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),
78
ae0af0523844 [svn] Call gnome_vfs_escape_path_string() before attempting to open the file.
msameer
parents: 0
diff changeset
74 escaped_file, g_mode, FALSE,
0
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
78
ae0af0523844 [svn] Call gnome_vfs_escape_path_string() before attempting to open the file.
msameer
parents: 0
diff changeset
87 g_free(escaped_file);
ae0af0523844 [svn] Call gnome_vfs_escape_path_string() before attempting to open the file.
msameer
parents: 0
diff changeset
88
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 return file;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 vfs_fclose(VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 gint ret = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 if (file->handle) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 if (gnome_vfs_close(file->handle) != GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 ret = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 g_free(file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 return ret;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 size_t
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 vfs_fread(gpointer ptr,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 size_t size,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 size_t nmemb,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 GnomeVFSFileSize bytes_read;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 result = gnome_vfs_read(file->handle, ptr, size * nmemb, &bytes_read);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 if (result == GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 return bytes_read;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 if (result == GNOME_VFS_ERROR_EOF)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 return 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 size_t
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 vfs_fwrite(gconstpointer ptr,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 size_t size,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 size_t nmemb,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 GnomeVFSFileSize bytes_written;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 result = gnome_vfs_write(file->handle, ptr, size * nmemb, &bytes_written);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 if (result == GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 return bytes_written;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 vfs_fseek(VFSFile * file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 glong offset,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 gint whence)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 GnomeVFSSeekPosition g_whence;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 switch (whence) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 case SEEK_SET:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 g_whence = GNOME_VFS_SEEK_START;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 case SEEK_CUR:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 g_whence = GNOME_VFS_SEEK_CURRENT;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 case SEEK_END:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 g_whence = GNOME_VFS_SEEK_END;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 g_warning("vfs_fseek: invalid whence value");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 result = gnome_vfs_seek(file->handle, g_whence, offset);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 if (result == GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 return 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 vfs_rewind(VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 vfs_fseek(file, 0L, SEEK_SET);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 glong
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 vfs_ftell(VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 GnomeVFSFileSize position;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 result = gnome_vfs_tell(file->handle, &position);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 if (result == GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 return position;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 vfs_file_test(const gchar * path,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 GFileTest test)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 GnomeVFSFileInfo info;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198 GFileTest file_test;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200 result = gnome_vfs_get_file_info(path, &info,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203 if (test == G_FILE_TEST_EXISTS)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204 return (result == GNOME_VFS_OK) ? TRUE : FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 else if (test == G_FILE_TEST_IS_EXECUTABLE)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206 return (info.permissions & GNOME_VFS_PERM_ACCESS_EXECUTABLE)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207 ? TRUE : FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209 switch (info.type) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 case GNOME_VFS_FILE_TYPE_REGULAR:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211 file_test = G_FILE_TEST_IS_REGULAR;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213 case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214 file_test = G_FILE_TEST_IS_SYMLINK;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216 case GNOME_VFS_FILE_TYPE_DIRECTORY:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217 file_test = G_FILE_TEST_IS_DIR;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222 if (test == file_test)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 vfs_is_writeable(const gchar * path)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 GnomeVFSFileInfo info;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233 if (gnome_vfs_get_file_info(path, &info, GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234 != GNOME_VFS_OK) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238 return (info.permissions & GNOME_VFS_PERM_ACCESS_WRITABLE ? TRUE : FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 vfs_truncate(VFSFile * file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 glong length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247 result = gnome_vfs_truncate_handle(file->handle, (GnomeVFSFileSize) length);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249 if (result == GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 return 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255 static gchar *strdup_exclude_chars(const gchar * s,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256 const gchar * c);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 mode_to_gnome_vfs(const gchar * mode,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 GnomeVFSOpenMode * g_mode,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 gboolean * truncate,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262 gboolean * append)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264 gchar *s;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266 *g_mode = GNOME_VFS_OPEN_RANDOM;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267 *truncate = *append = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 s = strdup_exclude_chars(mode, "bt");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 switch (s[0]) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271 case 'r':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272 *g_mode |= GNOME_VFS_OPEN_READ;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274 if (s[1] == '+')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275 *g_mode |= GNOME_VFS_OPEN_WRITE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278 case 'w':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279 case 'a':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280 *g_mode |= GNOME_VFS_OPEN_WRITE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282 if (s[0] == 'w')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283 *truncate = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285 *append = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 if (s[1] == '+')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 *g_mode |= GNOME_VFS_OPEN_READ;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292 g_warning("mode_to_gnome_vfs: unhandled mode character");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294 g_free(s);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 static gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298 strdup_exclude_chars(const gchar * s,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 const gchar * c)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301 gint i, j, k;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 gint newlen = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303 gchar *newstr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 gboolean found;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306 /* Calculate number of chars in new string */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307 for (i = 0; s[i] != '\0'; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308 found = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310 for (j = 0; j < strlen(c) && !found; j++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311 if (s[i] == c[j])
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312 found = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 if (!found)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315 newlen++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
318 newstr = g_malloc(newlen + 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320 /* Copy valid chars to new string */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321 for (i = k = 0; s[i] != '\0'; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322 found = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324 for (j = 0; j < strlen(c) && !found; j++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325 if (s[i] == c[j])
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326 found = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328 if (!found)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 newstr[k++] = s[i];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 newstr[k] = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
334 return newstr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335 }