annotate libaudacious/vfs_stdio.c @ 1982:cf33371e7ac3 trunk

[svn] - enhancements to the NewVFS probing layer.
author nenolod
date Sat, 18 Nov 2006 19:44:58 -0800
parents 976da06332df
children 93c59698f5fd
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
1460
411b4aaf928b [svn] fine
nemo
parents: 1459
diff changeset
2 * it under the terms of the GNU General Public License as published by
0
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
1459
705d4c089fce [svn] Fix postal code.
chainsaw
parents: 1458
diff changeset
13 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0
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 <stdio.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 #include <unistd.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 #include <sys/stat.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 #include <sys/types.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 VFSFile *
1975
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
24 stdio_vfs_fopen_impl(const gchar * path,
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 const gchar * mode)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27 VFSFile *file;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28
550
adee87ebe853 [svn] Sanity checking inside vfs_() functions.
nenolod
parents: 0
diff changeset
29 if (!path || !mode)
adee87ebe853 [svn] Sanity checking inside vfs_() functions.
nenolod
parents: 0
diff changeset
30 return NULL;
adee87ebe853 [svn] Sanity checking inside vfs_() functions.
nenolod
parents: 0
diff changeset
31
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 file = g_new(VFSFile, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 file->handle = fopen(path, mode);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 if (file->handle == NULL) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 g_free(file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 file = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 return file;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 gint
1975
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
45 stdio_vfs_fclose_impl(VFSFile * file)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 gint ret = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
49 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
50 return -1;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
51
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 if (file->handle) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 if (fclose(file->handle) != 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 ret = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 g_free(file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 return ret;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 size_t
1975
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
63 stdio_vfs_fread_impl(gpointer ptr,
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 size_t size,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 size_t nmemb,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
68 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
69 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
70
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 return fread(ptr, size, nmemb, file->handle);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 size_t
1975
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
75 stdio_vfs_fwrite_impl(gconstpointer ptr,
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 size_t size,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 size_t nmemb,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
80 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
81 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
82
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 return fwrite(ptr, size, nmemb, file->handle);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 gint
1975
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
87 stdio_vfs_getc_impl(VFSFile *stream)
1683
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
88 {
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
89 return getc( stream->handle );
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
90 }
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
91
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
92 gint
1975
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
93 stdio_vfs_ungetc_impl(gint c, VFSFile *stream)
1683
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
94 {
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
95 return ungetc( c , stream->handle );
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
96 }
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
97
e9c24e35bd76 [svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents: 1460
diff changeset
98 gint
1975
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
99 stdio_vfs_fseek_impl(VFSFile * file,
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 glong offset,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 gint whence)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
103 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
104 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
105
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 return fseek(file->handle, offset, whence);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 void
1975
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
110 stdio_vfs_rewind_impl(VFSFile * file)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
112 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
113 return;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
114
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 rewind(file->handle);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 glong
1975
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
119 stdio_vfs_ftell_impl(VFSFile * file)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
121 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
122 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
123
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 return ftell(file->handle);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 gboolean
1975
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
128 stdio_vfs_feof_impl(VFSFile * file)
811
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
129 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
130 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
131 return FALSE;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
132
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
133 return (gboolean) feof(file->handle);
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
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 gint
1975
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
137 stdio_vfs_truncate_impl(VFSFile * file, glong size)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
139 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
140 return -1;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
141
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 return ftruncate(fileno(file->handle), size);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 }
1975
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
144
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
145 VFSConstructor file_const = {
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
146 "file://",
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
147 stdio_vfs_fopen_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
148 stdio_vfs_fclose_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
149 stdio_vfs_fread_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
150 stdio_vfs_fwrite_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
151 stdio_vfs_getc_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
152 stdio_vfs_ungetc_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
153 stdio_vfs_fseek_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
154 stdio_vfs_rewind_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
155 stdio_vfs_ftell_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
156 stdio_vfs_feof_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
157 stdio_vfs_truncate_impl
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
158 };
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
159
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
160 VFSConstructor default_const = {
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
161 "/",
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
162 stdio_vfs_fopen_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
163 stdio_vfs_fclose_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
164 stdio_vfs_fread_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
165 stdio_vfs_fwrite_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
166 stdio_vfs_getc_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
167 stdio_vfs_ungetc_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
168 stdio_vfs_fseek_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
169 stdio_vfs_rewind_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
170 stdio_vfs_ftell_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
171 stdio_vfs_feof_impl,
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
172 stdio_vfs_truncate_impl
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
173 };
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
174
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
175 #if 0
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
176 gboolean
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
177 vfs_init(void)
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
178 {
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
179 vfs_register_transport(&default_const);
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
180 vfs_register_transport(&file_const);
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
181 return TRUE;
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
182 }
976da06332df [svn] - newvfs code, part 1
nenolod
parents: 1683
diff changeset
183 #endif