annotate libaudacious/vfs_gnome.c @ 576:c5ce7081a802 trunk

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