annotate libaudacious/vfs_gnome.c @ 1147:aef9aa10e0c0 trunk

[svn] - hookup buffer size option
author nenolod
date Sun, 04 Jun 2006 21:28:53 -0700
parents a17888ed66a8
children f12d7e208b43
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;
811
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
24 gboolean eof;
0
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 static void mode_to_gnome_vfs(const gchar * mode,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 GnomeVFSOpenMode * g_mode,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 gboolean * truncate,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 gboolean * append);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 vfs_init(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 if (!gnome_vfs_init())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 g_atexit(gnome_vfs_shutdown);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 VFSFile *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 vfs_fopen(const gchar * path,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 const gchar * mode)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 VFSFile *file;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 GnomeVFSResult g_result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 GnomeVFSOpenMode g_mode;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 gboolean truncate, append;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51
550
adee87ebe853 [svn] Sanity checking inside vfs_() functions.
nenolod
parents: 78
diff changeset
52 if (!path || !mode)
adee87ebe853 [svn] Sanity checking inside vfs_() functions.
nenolod
parents: 78
diff changeset
53 return NULL;
adee87ebe853 [svn] Sanity checking inside vfs_() functions.
nenolod
parents: 78
diff changeset
54
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 file = g_new(VFSFile, 1);
811
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
56 file->eof = FALSE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 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
59 gchar *escaped_file = gnome_vfs_escape_path_string(path);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 if (!truncate) {
78
ae0af0523844 [svn] Call gnome_vfs_escape_path_string() before attempting to open the file.
msameer
parents: 0
diff changeset
62 g_result = gnome_vfs_open(&(file->handle), escaped_file, g_mode);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 if (append && g_result == GNOME_VFS_ERROR_NOT_FOUND) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 g_result = gnome_vfs_create(&(file->handle),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 path, g_mode, TRUE,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 S_IRUSR | S_IWUSR |
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 S_IRGRP | S_IWGRP |
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 S_IROTH | S_IWOTH);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 if (append && g_result == GNOME_VFS_OK) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 g_result = gnome_vfs_seek(file->handle, GNOME_VFS_SEEK_END, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 if (g_result != GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 gnome_vfs_close(file->handle);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 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
79 escaped_file, g_mode, FALSE,
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 S_IRUSR | S_IWUSR |
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 if (g_result != GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 file->handle = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 if (file->handle == NULL) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 g_free(file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 file = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91
78
ae0af0523844 [svn] Call gnome_vfs_escape_path_string() before attempting to open the file.
msameer
parents: 0
diff changeset
92 g_free(escaped_file);
ae0af0523844 [svn] Call gnome_vfs_escape_path_string() before attempting to open the file.
msameer
parents: 0
diff changeset
93
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 return file;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 vfs_fclose(VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 gint ret = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
102 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
103 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
104
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 if (file->handle) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 if (gnome_vfs_close(file->handle) != GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 ret = -1;
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 g_free(file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 return ret;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 size_t
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 vfs_fread(gpointer ptr,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 size_t size,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 size_t nmemb,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 GnomeVFSFileSize bytes_read;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
124 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
125 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
126
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 result = gnome_vfs_read(file->handle, ptr, size * nmemb, &bytes_read);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 if (result == GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 return bytes_read;
811
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
130
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
131 if (result == GNOME_VFS_ERROR_EOF) {
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
132 file->eof = TRUE;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 return 0;
811
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
134 }
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
135
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
136 return -1;
0
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 size_t
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 vfs_fwrite(gconstpointer ptr,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 size_t size,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 size_t nmemb,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 GnomeVFSFileSize bytes_written;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
148 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
149 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
150
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 result = gnome_vfs_write(file->handle, ptr, size * nmemb, &bytes_written);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 if (result == GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 return bytes_written;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 vfs_fseek(VFSFile * file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 glong offset,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 gint whence)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 GnomeVFSSeekPosition g_whence;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
166 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
167 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
168
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 switch (whence) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 case SEEK_SET:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 g_whence = GNOME_VFS_SEEK_START;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 case SEEK_CUR:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 g_whence = GNOME_VFS_SEEK_CURRENT;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 case SEEK_END:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 g_whence = GNOME_VFS_SEEK_END;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 g_warning("vfs_fseek: invalid whence value");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 result = gnome_vfs_seek(file->handle, g_whence, offset);
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 0;
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 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 vfs_rewind(VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
195 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
196 return;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
197
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198 vfs_fseek(file, 0L, SEEK_SET);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 glong
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 vfs_ftell(VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 GnomeVFSFileSize position;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
207 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
208 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
209
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 result = gnome_vfs_tell(file->handle, &position);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212 if (result == GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213 return position;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218 gboolean
811
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
219 vfs_feof(VFSFile * file)
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
220 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
221 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
222 return FALSE;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
223
811
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
224 return file->eof;
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
225 }
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
226
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
227 gboolean
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228 vfs_file_test(const gchar * path,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 GFileTest test)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 GnomeVFSFileInfo info;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233 GFileTest file_test;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235 result = gnome_vfs_get_file_info(path, &info,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238 if (test == G_FILE_TEST_EXISTS)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239 return (result == GNOME_VFS_OK) ? TRUE : FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240 else if (test == G_FILE_TEST_IS_EXECUTABLE)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 return (info.permissions & GNOME_VFS_PERM_ACCESS_EXECUTABLE)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 ? TRUE : FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 switch (info.type) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 case GNOME_VFS_FILE_TYPE_REGULAR:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246 file_test = G_FILE_TEST_IS_REGULAR;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248 case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249 file_test = G_FILE_TEST_IS_SYMLINK;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251 case GNOME_VFS_FILE_TYPE_DIRECTORY:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252 file_test = G_FILE_TEST_IS_DIR;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257 if (test == file_test)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264 vfs_is_writeable(const gchar * path)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266 GnomeVFSFileInfo info;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268 if (gnome_vfs_get_file_info(path, &info, GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 != GNOME_VFS_OK) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273 return (info.permissions & GNOME_VFS_PERM_ACCESS_WRITABLE ? TRUE : FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277 vfs_truncate(VFSFile * file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278 glong length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280 GnomeVFSResult result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
282 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
283 return -1;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
284
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285 result = gnome_vfs_truncate_handle(file->handle, (GnomeVFSFileSize) length);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 if (result == GNOME_VFS_OK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 return 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290 return -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293 static gchar *strdup_exclude_chars(const gchar * s,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294 const gchar * c);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 mode_to_gnome_vfs(const gchar * mode,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298 GnomeVFSOpenMode * g_mode,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 gboolean * truncate,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300 gboolean * append)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 gchar *s;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 *g_mode = GNOME_VFS_OPEN_RANDOM;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305 *truncate = *append = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307 s = strdup_exclude_chars(mode, "bt");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308 switch (s[0]) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309 case 'r':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310 *g_mode |= GNOME_VFS_OPEN_READ;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312 if (s[1] == '+')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313 *g_mode |= GNOME_VFS_OPEN_WRITE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316 case 'w':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317 case 'a':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
318 *g_mode |= GNOME_VFS_OPEN_WRITE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320 if (s[0] == 'w')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321 *truncate = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 *append = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325 if (s[1] == '+')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326 *g_mode |= GNOME_VFS_OPEN_READ;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 g_warning("mode_to_gnome_vfs: unhandled mode character");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 g_free(s);
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 static gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336 strdup_exclude_chars(const gchar * s,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337 const gchar * c)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
338 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
339 gint i, j, k;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
340 gint newlen = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
341 gchar *newstr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342 gboolean found;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344 /* Calculate number of chars in new string */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345 for (i = 0; s[i] != '\0'; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
346 found = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
347
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
348 for (j = 0; j < strlen(c) && !found; j++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
349 if (s[i] == c[j])
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
350 found = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
351
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
352 if (!found)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
353 newlen++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
354 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
355
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
356 newstr = g_malloc(newlen + 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
357
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
358 /* Copy valid chars to new string */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
359 for (i = k = 0; s[i] != '\0'; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
360 found = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
361
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
362 for (j = 0; j < strlen(c) && !found; j++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
363 if (s[i] == c[j])
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
364 found = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
365
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
366 if (!found)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
367 newstr[k++] = s[i];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
368 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
369
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
370 newstr[k] = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
371
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
372 return newstr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
373 }