3097
|
1 /* Audacious
|
|
2 * Copyright (c) 2009 William Pitcock
|
|
3 *
|
|
4 * This program is free software; you can redistribute it and/or modify
|
|
5 * it under the terms of the GNU General Public License as published by
|
|
6 * the Free Software Foundation; either version 2 of the License, or
|
|
7 * (at your option) any later version.
|
|
8 *
|
|
9 * This program is distributed in the hope that it will be useful,
|
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 * GNU General Public License for more details.
|
|
13 *
|
|
14 * You should have received a copy of the GNU General Public License
|
|
15 * along with this program; if not, write to the Free Software
|
|
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
17 */
|
|
18
|
|
19 #include <audacious/plugin.h>
|
|
20
|
|
21 VFSFile *(*vfs_fopen_impl)(const gchar *path, const gchar *mode) = NULL;
|
|
22 gint (*vfs_fclose_impl)(VFSFile * file) = NULL;
|
|
23 size_t (*vfs_fread_impl)(gpointer ptr, size_t size, size_t nmemb, VFSFile *file) = NULL;
|
|
24 size_t (*vfs_fwrite_impl)(gconstpointer ptr, size_t size, size_t nmemb, VFSFile *file) = NULL;
|
|
25 gint (*vfs_getc_impl)(VFSFile *stream) = NULL;
|
|
26 gint (*vfs_ungetc_impl)(gint c, VFSFile *stream) = NULL;
|
|
27 gint (*vfs_fseek_impl)(VFSFile *file, glong offset, gint whence) = NULL;
|
|
28 void (*vfs_rewind_impl)(VFSFile *file) = NULL;
|
|
29 glong (*vfs_ftell_impl)(VFSFile *file) = NULL;
|
|
30 gboolean (*vfs_feof_impl)(VFSFile *file) = NULL;
|
|
31 gboolean (*vfs_truncate_impl)(VFSFile *file, glong length) = NULL;
|
|
32 off_t (*vfs_fsize_impl)(VFSFile *file) = NULL;
|
|
33
|
|
34 VFSFile *
|
|
35 vt_vfs_fopen_impl(const gchar *path, const gchar *mode)
|
|
36 {
|
|
37 VFSFile *ret;
|
|
38
|
|
39 ret = vfs_fopen_impl(path, mode);
|
|
40 g_print("fopen : path:%s : mode:%s : ret:%p\n", path, mode, ret);
|
|
41
|
|
42 return ret;
|
|
43 }
|
|
44
|
|
45 gint
|
|
46 vt_vfs_fclose_impl(VFSFile *file)
|
|
47 {
|
|
48 gint ret;
|
|
49
|
|
50 ret = vfs_fclose_impl(file);
|
|
51 g_print("fclose : file:%p : ret:%d\n", file, ret);
|
|
52
|
|
53 return ret;
|
|
54 }
|
|
55
|
|
56 size_t
|
|
57 vt_vfs_fread_impl(gpointer ptr, size_t size, size_t nmemb, VFSFile *file)
|
|
58 {
|
|
59 size_t ret;
|
|
60
|
|
61 ret = vfs_fread_impl(ptr, size, nmemb, file);
|
|
62 g_print("fread : size:%lu : nmemb:%lu : ret:%lu\n", size, nmemb, ret);
|
|
63
|
|
64 return ret;
|
|
65 }
|
|
66
|
|
67 size_t
|
|
68 vt_vfs_fwrite_impl(gconstpointer ptr, size_t size, size_t nmemb, VFSFile *file)
|
|
69 {
|
|
70 size_t ret;
|
|
71
|
|
72 ret = vfs_fwrite_impl(ptr, size, nmemb, file);
|
|
73 g_print("fwrite : size:%lu : nmemb:%lu : ret:%lu\n", size, nmemb, ret);
|
|
74
|
|
75 return ret;
|
|
76 }
|
|
77
|
|
78 gint
|
|
79 vt_vfs_getc_impl(VFSFile *stream)
|
|
80 {
|
|
81 gint ret;
|
|
82
|
|
83 ret = vfs_getc_impl(stream);
|
|
84 g_print("getc : ret:%d\n", ret);
|
|
85
|
|
86 return ret;
|
|
87 }
|
|
88
|
|
89 gint
|
|
90 vt_vfs_ungetc_impl(gint c, VFSFile *stream)
|
|
91 {
|
|
92 gint ret;
|
|
93
|
|
94 ret = vfs_ungetc_impl(c, stream);
|
|
95 g_print("ungetc : c:%d : ret:%d\n", c, ret);
|
|
96
|
|
97 return ret;
|
|
98 }
|
|
99
|
|
100 gint
|
|
101 vt_vfs_fseek_impl(VFSFile *file, glong offset, gint whence)
|
|
102 {
|
|
103 gint ret;
|
|
104
|
|
105 ret = vfs_fseek_impl(file, offset, whence);
|
|
106 g_print("fseek : offset:%ld : whence:%d : ret:%d\n", offset, whence, ret);
|
|
107
|
|
108 return ret;
|
|
109 }
|
|
110
|
|
111 void
|
|
112 vt_vfs_rewind_impl(VFSFile *file)
|
|
113 {
|
|
114 g_print("rewind\n");
|
|
115 vfs_rewind_impl(file);
|
|
116 }
|
|
117
|
|
118 glong
|
|
119 vt_vfs_ftell_impl(VFSFile *file)
|
|
120 {
|
|
121 glong ret;
|
|
122
|
|
123 ret = vfs_ftell_impl(file);
|
|
124 g_print("ftell : ret:%ld\n", ret);
|
|
125
|
|
126 return ret;
|
|
127 }
|
|
128
|
|
129 gboolean
|
|
130 vt_vfs_feof_impl(VFSFile *file)
|
|
131 {
|
|
132 gboolean ret;
|
|
133
|
|
134 ret = vfs_feof_impl(file);
|
|
135 g_print("feof : ret:%d\n", ret);
|
|
136
|
|
137 return ret;
|
|
138 }
|
|
139
|
|
140 gboolean
|
|
141 vt_vfs_truncate_impl(VFSFile *file, glong length)
|
|
142 {
|
|
143 gboolean ret;
|
|
144
|
|
145 ret = vfs_truncate_impl(file, length);
|
|
146 g_print("truncate : length:%ld : ret:%d\n", length, ret);
|
|
147
|
|
148 return ret;
|
|
149 }
|
|
150
|
|
151 off_t
|
|
152 vt_vfs_fsize_impl(VFSFile *file)
|
|
153 {
|
|
154 off_t ret;
|
|
155
|
|
156 ret = vfs_fsize_impl(file);
|
|
157 g_print("fsize : ret:%lu\n", ret);
|
|
158
|
|
159 return ret;
|
|
160 }
|
|
161
|
|
162 void
|
|
163 patch_vfs(void)
|
|
164 {
|
|
165 vfs_fopen_impl = aud_vfs_fopen;
|
|
166 vfs_fclose_impl = aud_vfs_fclose;
|
|
167 vfs_fread_impl = aud_vfs_fread;
|
|
168 vfs_fwrite_impl = aud_vfs_fwrite;
|
|
169 vfs_getc_impl = aud_vfs_getc;
|
|
170 vfs_ungetc_impl = aud_vfs_ungetc;
|
|
171 vfs_fseek_impl = aud_vfs_fseek;
|
|
172 vfs_rewind_impl = aud_vfs_rewind;
|
|
173 vfs_ftell_impl = aud_vfs_ftell;
|
|
174 vfs_feof_impl = aud_vfs_feof;
|
|
175 vfs_truncate_impl = aud_vfs_truncate;
|
|
176 vfs_fsize_impl = aud_vfs_fsize;
|
|
177
|
|
178 aud_vfs_fopen = vt_vfs_fopen_impl;
|
|
179 aud_vfs_fclose = vt_vfs_fclose_impl;
|
|
180 aud_vfs_fread = vt_vfs_fread_impl;
|
|
181 aud_vfs_fwrite = vt_vfs_fwrite_impl;
|
|
182 aud_vfs_getc = vt_vfs_getc_impl;
|
|
183 aud_vfs_ungetc = vt_vfs_ungetc_impl;
|
|
184 aud_vfs_fseek = vt_vfs_fseek_impl;
|
|
185 aud_vfs_rewind = vt_vfs_rewind_impl;
|
|
186 aud_vfs_ftell = vt_vfs_ftell_impl;
|
|
187 aud_vfs_feof = vt_vfs_feof_impl;
|
|
188 aud_vfs_truncate = vt_vfs_truncate_impl;
|
|
189 aud_vfs_fsize = vt_vfs_fsize_impl;
|
|
190 }
|
|
191
|
|
192 void
|
|
193 unpatch_vfs(void)
|
|
194 {
|
|
195 aud_vfs_fopen = vfs_fopen_impl;
|
|
196 aud_vfs_fclose = vfs_fclose_impl;
|
|
197 aud_vfs_fread = vfs_fread_impl;
|
|
198 aud_vfs_fwrite = vfs_fwrite_impl;
|
|
199 aud_vfs_getc = vfs_getc_impl;
|
|
200 aud_vfs_ungetc = vfs_ungetc_impl;
|
|
201 aud_vfs_fseek = vfs_fseek_impl;
|
|
202 aud_vfs_rewind = vfs_rewind_impl;
|
|
203 aud_vfs_ftell = vfs_ftell_impl;
|
|
204 aud_vfs_feof = vfs_feof_impl;
|
|
205 aud_vfs_truncate = vfs_truncate_impl;
|
|
206 aud_vfs_fsize = vfs_fsize_impl;
|
|
207 }
|
|
208
|
|
209 static GeneralPlugin vfstrace_plugin =
|
|
210 {
|
|
211 .description = "VFSTrace",
|
|
212 .init = patch_vfs,
|
|
213 .cleanup = unpatch_vfs,
|
|
214 };
|
|
215
|
|
216 GeneralPlugin *vfstrace_gplist[] = { &vfstrace_plugin, NULL };
|
|
217 SIMPLE_GENERAL_PLUGIN(vfstrace, vfstrace_gplist);
|
|
218
|