Mercurial > audlegacy-plugins
annotate src/stdio/stdio.c @ 334:a9f1bd76a3e6 trunk
[svn] - apply_xform(): check for NULL vfield (broken scripts)
- add tan(), asin(), acos(), atan(), log() to script engine.
author | nenolod |
---|---|
date | Tue, 05 Dec 2006 03:40:04 -0800 |
parents | 90a843d02970 |
children | 1d81ea250dce |
rev | line source |
---|---|
306 | 1 /* Audacious |
2 * Copyright (c) 2006 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/vfs.h> | |
20 #include <audacious/plugin.h> | |
21 #include <stdio.h> | |
22 | |
23 #include <unistd.h> | |
24 #include <sys/stat.h> | |
25 #include <sys/types.h> | |
26 | |
27 VFSFile * | |
28 stdio_vfs_fopen_impl(const gchar * path, | |
29 const gchar * mode) | |
30 { | |
31 VFSFile *file; | |
32 | |
33 if (!path || !mode) | |
34 return NULL; | |
35 | |
36 file = g_new(VFSFile, 1); | |
37 | |
38 file->handle = fopen(path, mode); | |
39 | |
40 if (file->handle == NULL) { | |
41 g_free(file); | |
42 file = NULL; | |
43 } | |
44 | |
45 return file; | |
46 } | |
47 | |
48 gint | |
49 stdio_vfs_fclose_impl(VFSFile * file) | |
50 { | |
51 gint ret = 0; | |
52 | |
53 if (file == NULL) | |
54 return -1; | |
55 | |
326
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
56 if (file->handle) |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
57 { |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
58 FILE *handle = (FILE *) file->handle; |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
59 |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
60 if (fclose(handle) != 0) |
306 | 61 ret = -1; |
62 } | |
63 | |
64 return ret; | |
65 } | |
66 | |
67 size_t | |
68 stdio_vfs_fread_impl(gpointer ptr, | |
69 size_t size, | |
70 size_t nmemb, | |
71 VFSFile * file) | |
72 { | |
326
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
73 FILE *handle; |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
74 |
306 | 75 if (file == NULL) |
76 return 0; | |
77 | |
326
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
78 handle = (FILE *) file->handle; |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
79 |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
80 return fread(ptr, size, nmemb, handle); |
306 | 81 } |
82 | |
83 size_t | |
84 stdio_vfs_fwrite_impl(gconstpointer ptr, | |
85 size_t size, | |
86 size_t nmemb, | |
87 VFSFile * file) | |
88 { | |
326
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
89 FILE *handle; |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
90 |
306 | 91 if (file == NULL) |
92 return 0; | |
93 | |
326
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
94 handle = (FILE *) file->handle; |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
95 |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
96 return fwrite(ptr, size, nmemb, handle); |
306 | 97 } |
98 | |
99 gint | |
100 stdio_vfs_getc_impl(VFSFile *stream) | |
101 { | |
326
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
102 FILE *handle = (FILE *) stream->handle; |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
103 |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
104 return getc( handle ); |
306 | 105 } |
106 | |
107 gint | |
108 stdio_vfs_ungetc_impl(gint c, VFSFile *stream) | |
109 { | |
326
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
110 FILE *handle = (FILE *) stream->handle; |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
111 |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
112 return ungetc( c , handle ); |
306 | 113 } |
114 | |
115 gint | |
116 stdio_vfs_fseek_impl(VFSFile * file, | |
117 glong offset, | |
118 gint whence) | |
119 { | |
326
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
120 FILE *handle; |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
121 |
306 | 122 if (file == NULL) |
123 return 0; | |
124 | |
326
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
125 handle = (FILE *) file->handle; |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
126 |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
127 return fseek(handle, offset, whence); |
306 | 128 } |
129 | |
130 void | |
131 stdio_vfs_rewind_impl(VFSFile * file) | |
132 { | |
326
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
133 FILE *handle; |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
134 |
306 | 135 if (file == NULL) |
136 return; | |
137 | |
326
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
138 handle = (FILE *) file->handle; |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
139 |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
140 rewind(handle); |
306 | 141 } |
142 | |
143 glong | |
144 stdio_vfs_ftell_impl(VFSFile * file) | |
145 { | |
326
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
146 FILE *handle; |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
147 |
306 | 148 if (file == NULL) |
149 return 0; | |
150 | |
326
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
151 handle = (FILE *) file->handle; |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
152 |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
153 return ftell(handle); |
306 | 154 } |
155 | |
156 gboolean | |
157 stdio_vfs_feof_impl(VFSFile * file) | |
158 { | |
326
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
159 FILE *handle; |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
160 |
306 | 161 if (file == NULL) |
162 return FALSE; | |
163 | |
326
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
164 handle = (FILE *) file->handle; |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
165 |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
166 return (gboolean) feof(handle); |
306 | 167 } |
168 | |
169 gint | |
170 stdio_vfs_truncate_impl(VFSFile * file, glong size) | |
171 { | |
326
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
172 FILE *handle; |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
173 |
306 | 174 if (file == NULL) |
175 return -1; | |
176 | |
326
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
177 handle = (FILE *) file->handle; |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
178 |
90a843d02970
[svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents:
306
diff
changeset
|
179 return ftruncate(fileno(handle), size); |
306 | 180 } |
181 | |
182 VFSConstructor file_const = { | |
183 "file://", | |
184 stdio_vfs_fopen_impl, | |
185 stdio_vfs_fclose_impl, | |
186 stdio_vfs_fread_impl, | |
187 stdio_vfs_fwrite_impl, | |
188 stdio_vfs_getc_impl, | |
189 stdio_vfs_ungetc_impl, | |
190 stdio_vfs_fseek_impl, | |
191 stdio_vfs_rewind_impl, | |
192 stdio_vfs_ftell_impl, | |
193 stdio_vfs_feof_impl, | |
194 stdio_vfs_truncate_impl | |
195 }; | |
196 | |
197 VFSConstructor default_const = { | |
198 "/", | |
199 stdio_vfs_fopen_impl, | |
200 stdio_vfs_fclose_impl, | |
201 stdio_vfs_fread_impl, | |
202 stdio_vfs_fwrite_impl, | |
203 stdio_vfs_getc_impl, | |
204 stdio_vfs_ungetc_impl, | |
205 stdio_vfs_fseek_impl, | |
206 stdio_vfs_rewind_impl, | |
207 stdio_vfs_ftell_impl, | |
208 stdio_vfs_feof_impl, | |
209 stdio_vfs_truncate_impl | |
210 }; | |
211 | |
212 static void init(void) | |
213 { | |
214 vfs_register_transport(&default_const); | |
215 vfs_register_transport(&file_const); | |
216 } | |
217 | |
218 static void cleanup(void) | |
219 { | |
220 #if 0 | |
221 vfs_unregister_transport(&default_const); | |
222 vfs_unregister_transport(&file_const); | |
223 #endif | |
224 } | |
225 | |
226 LowlevelPlugin llp_stdio = { | |
227 NULL, | |
228 NULL, | |
229 "file:// URI Transport", | |
230 init, | |
231 cleanup, | |
232 }; | |
233 | |
234 LowlevelPlugin *get_lplugin_info(void) | |
235 { | |
236 return &llp_stdio; | |
237 } | |
238 |