Mercurial > audlegacy-plugins
comparison src/stdio/stdio.c @ 1978:fa9f85cebade
s/vfs_/aud_vfs_/g
| author | William Pitcock <nenolod@atheme.org> |
|---|---|
| date | Sun, 07 Oct 2007 00:25:33 -0500 |
| parents | 0d2f57214b0c |
| children | 6e2070ea35e7 |
comparison
equal
deleted
inserted
replaced
| 1977:5a6b60ceaa0f | 1978:fa9f85cebade |
|---|---|
| 26 #include <sys/types.h> | 26 #include <sys/types.h> |
| 27 | 27 |
| 28 #include <string.h> | 28 #include <string.h> |
| 29 | 29 |
| 30 static gchar * | 30 static gchar * |
| 31 vfs_stdio_urldecode_path(const gchar * encoded_path) | 31 aud_vfs_stdio_urldecode_path(const gchar * encoded_path) |
| 32 { | 32 { |
| 33 const gchar *cur, *ext; | 33 const gchar *cur, *ext; |
| 34 gchar *path, *tmp; | 34 gchar *path, *tmp; |
| 35 gint realchar; | 35 gint realchar; |
| 36 | 36 |
| 69 g_free(tmp); | 69 g_free(tmp); |
| 70 return path; | 70 return path; |
| 71 } | 71 } |
| 72 | 72 |
| 73 VFSFile * | 73 VFSFile * |
| 74 stdio_vfs_fopen_impl(const gchar * path, | 74 stdio_aud_vfs_fopen_impl(const gchar * path, |
| 75 const gchar * mode) | 75 const gchar * mode) |
| 76 { | 76 { |
| 77 VFSFile *file; | 77 VFSFile *file; |
| 78 gchar *decpath; | 78 gchar *decpath; |
| 79 | 79 |
| 80 if (!path || !mode) | 80 if (!path || !mode) |
| 81 return NULL; | 81 return NULL; |
| 82 | 82 |
| 83 decpath = vfs_stdio_urldecode_path(path); | 83 decpath = aud_vfs_stdio_urldecode_path(path); |
| 84 | 84 |
| 85 file = g_new(VFSFile, 1); | 85 file = g_new(VFSFile, 1); |
| 86 | 86 |
| 87 file->handle = fopen(decpath != NULL ? decpath : path, mode); | 87 file->handle = fopen(decpath != NULL ? decpath : path, mode); |
| 88 | 88 |
| 96 | 96 |
| 97 return file; | 97 return file; |
| 98 } | 98 } |
| 99 | 99 |
| 100 gint | 100 gint |
| 101 stdio_vfs_fclose_impl(VFSFile * file) | 101 stdio_aud_vfs_fclose_impl(VFSFile * file) |
| 102 { | 102 { |
| 103 gint ret = 0; | 103 gint ret = 0; |
| 104 | 104 |
| 105 if (file == NULL) | 105 if (file == NULL) |
| 106 return -1; | 106 return -1; |
| 116 | 116 |
| 117 return ret; | 117 return ret; |
| 118 } | 118 } |
| 119 | 119 |
| 120 size_t | 120 size_t |
| 121 stdio_vfs_fread_impl(gpointer ptr, | 121 stdio_aud_vfs_fread_impl(gpointer ptr, |
| 122 size_t size, | 122 size_t size, |
| 123 size_t nmemb, | 123 size_t nmemb, |
| 124 VFSFile * file) | 124 VFSFile * file) |
| 125 { | 125 { |
| 126 FILE *handle; | 126 FILE *handle; |
| 132 | 132 |
| 133 return fread(ptr, size, nmemb, handle); | 133 return fread(ptr, size, nmemb, handle); |
| 134 } | 134 } |
| 135 | 135 |
| 136 size_t | 136 size_t |
| 137 stdio_vfs_fwrite_impl(gconstpointer ptr, | 137 stdio_aud_vfs_fwrite_impl(gconstpointer ptr, |
| 138 size_t size, | 138 size_t size, |
| 139 size_t nmemb, | 139 size_t nmemb, |
| 140 VFSFile * file) | 140 VFSFile * file) |
| 141 { | 141 { |
| 142 FILE *handle; | 142 FILE *handle; |
| 148 | 148 |
| 149 return fwrite(ptr, size, nmemb, handle); | 149 return fwrite(ptr, size, nmemb, handle); |
| 150 } | 150 } |
| 151 | 151 |
| 152 gint | 152 gint |
| 153 stdio_vfs_getc_impl(VFSFile *stream) | 153 stdio_aud_vfs_getc_impl(VFSFile *stream) |
| 154 { | 154 { |
| 155 FILE *handle = (FILE *) stream->handle; | 155 FILE *handle = (FILE *) stream->handle; |
| 156 | 156 |
| 157 return getc( handle ); | 157 return getc( handle ); |
| 158 } | 158 } |
| 159 | 159 |
| 160 gint | 160 gint |
| 161 stdio_vfs_ungetc_impl(gint c, VFSFile *stream) | 161 stdio_aud_vfs_ungetc_impl(gint c, VFSFile *stream) |
| 162 { | 162 { |
| 163 FILE *handle = (FILE *) stream->handle; | 163 FILE *handle = (FILE *) stream->handle; |
| 164 | 164 |
| 165 return ungetc( c , handle ); | 165 return ungetc( c , handle ); |
| 166 } | 166 } |
| 167 | 167 |
| 168 gint | 168 gint |
| 169 stdio_vfs_fseek_impl(VFSFile * file, | 169 stdio_aud_vfs_fseek_impl(VFSFile * file, |
| 170 glong offset, | 170 glong offset, |
| 171 gint whence) | 171 gint whence) |
| 172 { | 172 { |
| 173 FILE *handle; | 173 FILE *handle; |
| 174 | 174 |
| 179 | 179 |
| 180 return fseek(handle, offset, whence); | 180 return fseek(handle, offset, whence); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void | 183 void |
| 184 stdio_vfs_rewind_impl(VFSFile * file) | 184 stdio_aud_vfs_rewind_impl(VFSFile * file) |
| 185 { | 185 { |
| 186 FILE *handle; | 186 FILE *handle; |
| 187 | 187 |
| 188 if (file == NULL) | 188 if (file == NULL) |
| 189 return; | 189 return; |
| 192 | 192 |
| 193 rewind(handle); | 193 rewind(handle); |
| 194 } | 194 } |
| 195 | 195 |
| 196 glong | 196 glong |
| 197 stdio_vfs_ftell_impl(VFSFile * file) | 197 stdio_aud_vfs_ftell_impl(VFSFile * file) |
| 198 { | 198 { |
| 199 FILE *handle; | 199 FILE *handle; |
| 200 | 200 |
| 201 if (file == NULL) | 201 if (file == NULL) |
| 202 return 0; | 202 return 0; |
| 205 | 205 |
| 206 return ftell(handle); | 206 return ftell(handle); |
| 207 } | 207 } |
| 208 | 208 |
| 209 gboolean | 209 gboolean |
| 210 stdio_vfs_feof_impl(VFSFile * file) | 210 stdio_aud_vfs_feof_impl(VFSFile * file) |
| 211 { | 211 { |
| 212 FILE *handle; | 212 FILE *handle; |
| 213 | 213 |
| 214 if (file == NULL) | 214 if (file == NULL) |
| 215 return FALSE; | 215 return FALSE; |
| 218 | 218 |
| 219 return (gboolean) feof(handle); | 219 return (gboolean) feof(handle); |
| 220 } | 220 } |
| 221 | 221 |
| 222 gint | 222 gint |
| 223 stdio_vfs_truncate_impl(VFSFile * file, glong size) | 223 stdio_aud_vfs_truncate_impl(VFSFile * file, glong size) |
| 224 { | 224 { |
| 225 FILE *handle; | 225 FILE *handle; |
| 226 | 226 |
| 227 if (file == NULL) | 227 if (file == NULL) |
| 228 return -1; | 228 return -1; |
| 231 | 231 |
| 232 return ftruncate(fileno(handle), size); | 232 return ftruncate(fileno(handle), size); |
| 233 } | 233 } |
| 234 | 234 |
| 235 off_t | 235 off_t |
| 236 stdio_vfs_fsize_impl(VFSFile * file) | 236 stdio_aud_vfs_fsize_impl(VFSFile * file) |
| 237 { | 237 { |
| 238 FILE *handle; | 238 FILE *handle; |
| 239 struct stat s; | 239 struct stat s; |
| 240 | 240 |
| 241 if (file == NULL) | 241 if (file == NULL) |
| 249 return s.st_size; | 249 return s.st_size; |
| 250 } | 250 } |
| 251 | 251 |
| 252 VFSConstructor file_const = { | 252 VFSConstructor file_const = { |
| 253 .uri_id = "file://", | 253 .uri_id = "file://", |
| 254 .vfs_fopen_impl = stdio_vfs_fopen_impl, | 254 .aud_vfs_fopen_impl = stdio_aud_vfs_fopen_impl, |
| 255 .vfs_fclose_impl = stdio_vfs_fclose_impl, | 255 .aud_vfs_fclose_impl = stdio_aud_vfs_fclose_impl, |
| 256 .vfs_fread_impl = stdio_vfs_fread_impl, | 256 .aud_vfs_fread_impl = stdio_aud_vfs_fread_impl, |
| 257 .vfs_fwrite_impl = stdio_vfs_fwrite_impl, | 257 .aud_vfs_fwrite_impl = stdio_aud_vfs_fwrite_impl, |
| 258 .vfs_getc_impl = stdio_vfs_getc_impl, | 258 .aud_vfs_getc_impl = stdio_aud_vfs_getc_impl, |
| 259 .vfs_ungetc_impl = stdio_vfs_ungetc_impl, | 259 .aud_vfs_ungetc_impl = stdio_aud_vfs_ungetc_impl, |
| 260 .vfs_fseek_impl = stdio_vfs_fseek_impl, | 260 .aud_vfs_fseek_impl = stdio_aud_vfs_fseek_impl, |
| 261 .vfs_rewind_impl = stdio_vfs_rewind_impl, | 261 .aud_vfs_rewind_impl = stdio_aud_vfs_rewind_impl, |
| 262 .vfs_ftell_impl = stdio_vfs_ftell_impl, | 262 .aud_vfs_ftell_impl = stdio_aud_vfs_ftell_impl, |
| 263 .vfs_feof_impl = stdio_vfs_feof_impl, | 263 .aud_vfs_feof_impl = stdio_aud_vfs_feof_impl, |
| 264 .vfs_truncate_impl = stdio_vfs_truncate_impl, | 264 .aud_vfs_truncate_impl = stdio_aud_vfs_truncate_impl, |
| 265 .vfs_fsize_impl = stdio_vfs_fsize_impl | 265 .aud_vfs_fsize_impl = stdio_aud_vfs_fsize_impl |
| 266 }; | 266 }; |
| 267 | 267 |
| 268 static void init(void) | 268 static void init(void) |
| 269 { | 269 { |
| 270 vfs_register_transport(&file_const); | 270 aud_vfs_register_transport(&file_const); |
| 271 } | 271 } |
| 272 | 272 |
| 273 static void cleanup(void) | 273 static void cleanup(void) |
| 274 { | 274 { |
| 275 #if 0 | 275 #if 0 |
| 276 vfs_unregister_transport(&file_const); | 276 aud_vfs_unregister_transport(&file_const); |
| 277 #endif | 277 #endif |
| 278 } | 278 } |
| 279 | 279 |
| 280 DECLARE_PLUGIN(stdio, init, cleanup, NULL, NULL, NULL, NULL, NULL, NULL); | 280 DECLARE_PLUGIN(stdio, init, cleanup, NULL, NULL, NULL, NULL, NULL, NULL); |
