annotate src/stdio/stdio.c @ 2147:e49d9b0ee308

Change my mail.
author Jonathan Schleifer <js@h3c.de>
date Thu, 01 Nov 2007 15:37:43 +0100
parents 2ffc6a69fcd1
children bd3a24b39058
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
1 /* Audacious
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
2 * Copyright (c) 2006 William Pitcock
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
3 *
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
7 * (at your option) any later version.
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
8 *
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
12 * GNU General Public License for more details.
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
13 *
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
15 * along with this program; if not, write to the Free Software
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
17 */
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
18
1957
0d2f57214b0c Use C99 initializer.
Matti Hamalainen <ccr@tnsp.org>
parents: 1950
diff changeset
19 #include "config.h"
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
20 #include <audacious/plugin.h>
1950
2ebeb7816c5e Change from "" to <>-style includes. With thanks to ccr for the correct sed voodoo.
chainsaw@localhost
parents: 1935
diff changeset
21 #include <audacious/strings.h>
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
22 #include <stdio.h>
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
23
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
24 #include <unistd.h>
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
25 #include <sys/stat.h>
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
26 #include <sys/types.h>
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
27
500
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
28 #include <string.h>
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
29
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
30 static gchar *
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1957
diff changeset
31 aud_vfs_stdio_urldecode_path(const gchar * encoded_path)
500
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
32 {
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
33 const gchar *cur, *ext;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
34 gchar *path, *tmp;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
35 gint realchar;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
36
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
37 if (!encoded_path)
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
38 return NULL;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
39
2050
2ffc6a69fcd1 string API calls -> vtable
William Pitcock <nenolod@atheme.org>
parents: 1980
diff changeset
40 if (!aud_str_has_prefix_nocase(encoded_path, "file:"))
500
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
41 return NULL;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
42
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
43 cur = encoded_path + 5;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
44
2050
2ffc6a69fcd1 string API calls -> vtable
William Pitcock <nenolod@atheme.org>
parents: 1980
diff changeset
45 if (aud_str_has_prefix_nocase(cur, "//localhost"))
500
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
46 cur += 11;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
47
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
48 if (*cur == '/')
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
49 while (cur[1] == '/')
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
50 cur++;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
51
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
52 tmp = g_malloc0(strlen(cur) + 1);
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
53
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
54 while ((ext = strchr(cur, '%')) != NULL) {
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
55 strncat(tmp, cur, ext - cur);
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
56 ext++;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
57 cur = ext + 2;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
58 if (!sscanf(ext, "%2x", &realchar)) {
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
59 /* Assume it is a literal '%'. Several file
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
60 * managers send unencoded file: urls on drag
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
61 * and drop. */
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
62 realchar = '%';
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
63 cur -= 2;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
64 }
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
65 tmp[strlen(tmp)] = realchar;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
66 }
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
67
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
68 path = g_strconcat(tmp, cur, NULL);
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
69 g_free(tmp);
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
70 return path;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
71 }
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
72
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
73 VFSFile *
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1957
diff changeset
74 stdio_aud_vfs_fopen_impl(const gchar * path,
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
75 const gchar * mode)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
76 {
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
77 VFSFile *file;
500
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
78 gchar *decpath;
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
79
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
80 if (!path || !mode)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
81 return NULL;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
82
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1957
diff changeset
83 decpath = aud_vfs_stdio_urldecode_path(path);
500
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
84
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
85 file = g_new(VFSFile, 1);
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
86
500
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
87 file->handle = fopen(decpath != NULL ? decpath : path, mode);
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
88
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
89 if (decpath != NULL)
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
90 g_free(decpath);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
91
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
92 if (file->handle == NULL) {
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
93 g_free(file);
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
94 file = NULL;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
95 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
96
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
97 return file;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
98 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
99
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
100 gint
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1957
diff changeset
101 stdio_aud_vfs_fclose_impl(VFSFile * file)
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
102 {
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
103 gint ret = 0;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
104
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
105 if (file == NULL)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
106 return -1;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
107
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
108 if (file->handle)
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
109 {
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
110 FILE *handle = (FILE *) file->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 if (fclose(handle) != 0)
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
113 ret = -1;
1228
01efa0e5b554 file->handle should be cleared on close, otherwise it can lead to double free.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1210
diff changeset
114 file->handle = NULL;
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
115 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
116
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
117 return ret;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
118 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
119
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
120 size_t
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1957
diff changeset
121 stdio_aud_vfs_fread_impl(gpointer ptr,
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
122 size_t size,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
123 size_t nmemb,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
124 VFSFile * file)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
125 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
126 FILE *handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
127
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
128 if (file == NULL)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
129 return 0;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
130
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
131 handle = (FILE *) file->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
132
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
133 return fread(ptr, size, nmemb, handle);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
134 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
135
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
136 size_t
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1957
diff changeset
137 stdio_aud_vfs_fwrite_impl(gconstpointer ptr,
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
138 size_t size,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
139 size_t nmemb,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
140 VFSFile * file)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
141 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
142 FILE *handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
143
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
144 if (file == NULL)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
145 return 0;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
146
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
147 handle = (FILE *) file->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
148
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
149 return fwrite(ptr, size, nmemb, handle);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
150 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
151
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
152 gint
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1957
diff changeset
153 stdio_aud_vfs_getc_impl(VFSFile *stream)
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
154 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
155 FILE *handle = (FILE *) stream->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
156
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
157 return getc( handle );
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
158 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
159
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
160 gint
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1957
diff changeset
161 stdio_aud_vfs_ungetc_impl(gint c, VFSFile *stream)
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
162 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
163 FILE *handle = (FILE *) stream->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
164
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
165 return ungetc( c , handle );
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
166 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
167
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
168 gint
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1957
diff changeset
169 stdio_aud_vfs_fseek_impl(VFSFile * file,
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
170 glong offset,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
171 gint whence)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
172 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
173 FILE *handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
174
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
175 if (file == NULL)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
176 return 0;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
177
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
178 handle = (FILE *) file->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
179
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
180 return fseek(handle, offset, whence);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
181 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
182
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
183 void
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1957
diff changeset
184 stdio_aud_vfs_rewind_impl(VFSFile * file)
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
185 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
186 FILE *handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
187
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
188 if (file == NULL)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
189 return;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
190
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
191 handle = (FILE *) file->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
192
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
193 rewind(handle);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
194 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
195
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
196 glong
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1957
diff changeset
197 stdio_aud_vfs_ftell_impl(VFSFile * file)
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
198 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
199 FILE *handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
200
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
201 if (file == NULL)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
202 return 0;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
203
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
204 handle = (FILE *) file->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
205
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
206 return ftell(handle);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
207 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
208
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
209 gboolean
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1957
diff changeset
210 stdio_aud_vfs_feof_impl(VFSFile * file)
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
211 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
212 FILE *handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
213
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
214 if (file == NULL)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
215 return FALSE;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
216
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
217 handle = (FILE *) file->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
218
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
219 return (gboolean) feof(handle);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
220 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
221
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
222 gint
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1957
diff changeset
223 stdio_aud_vfs_truncate_impl(VFSFile * file, glong size)
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
224 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
225 FILE *handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
226
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
227 if (file == NULL)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
228 return -1;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
229
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
230 handle = (FILE *) file->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
231
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
232 return ftruncate(fileno(handle), size);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
233 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
234
965
ertzing
parents: 500
diff changeset
235 off_t
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1957
diff changeset
236 stdio_aud_vfs_fsize_impl(VFSFile * file)
965
ertzing
parents: 500
diff changeset
237 {
ertzing
parents: 500
diff changeset
238 FILE *handle;
ertzing
parents: 500
diff changeset
239 struct stat s;
ertzing
parents: 500
diff changeset
240
ertzing
parents: 500
diff changeset
241 if (file == NULL)
ertzing
parents: 500
diff changeset
242 return -1;
ertzing
parents: 500
diff changeset
243
ertzing
parents: 500
diff changeset
244 handle = (FILE *) file->handle;
ertzing
parents: 500
diff changeset
245
ertzing
parents: 500
diff changeset
246 if (-1 == fstat(fileno(handle), &s))
ertzing
parents: 500
diff changeset
247 return -1;
ertzing
parents: 500
diff changeset
248
ertzing
parents: 500
diff changeset
249 return s.st_size;
ertzing
parents: 500
diff changeset
250 }
ertzing
parents: 500
diff changeset
251
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
252 VFSConstructor file_const = {
1957
0d2f57214b0c Use C99 initializer.
Matti Hamalainen <ccr@tnsp.org>
parents: 1950
diff changeset
253 .uri_id = "file://",
1980
6e2070ea35e7 more work
William Pitcock <nenolod@atheme.org>
parents: 1978
diff changeset
254 .vfs_fopen_impl = stdio_aud_vfs_fopen_impl,
6e2070ea35e7 more work
William Pitcock <nenolod@atheme.org>
parents: 1978
diff changeset
255 .vfs_fclose_impl = stdio_aud_vfs_fclose_impl,
6e2070ea35e7 more work
William Pitcock <nenolod@atheme.org>
parents: 1978
diff changeset
256 .vfs_fread_impl = stdio_aud_vfs_fread_impl,
6e2070ea35e7 more work
William Pitcock <nenolod@atheme.org>
parents: 1978
diff changeset
257 .vfs_fwrite_impl = stdio_aud_vfs_fwrite_impl,
6e2070ea35e7 more work
William Pitcock <nenolod@atheme.org>
parents: 1978
diff changeset
258 .vfs_getc_impl = stdio_aud_vfs_getc_impl,
6e2070ea35e7 more work
William Pitcock <nenolod@atheme.org>
parents: 1978
diff changeset
259 .vfs_ungetc_impl = stdio_aud_vfs_ungetc_impl,
6e2070ea35e7 more work
William Pitcock <nenolod@atheme.org>
parents: 1978
diff changeset
260 .vfs_fseek_impl = stdio_aud_vfs_fseek_impl,
6e2070ea35e7 more work
William Pitcock <nenolod@atheme.org>
parents: 1978
diff changeset
261 .vfs_rewind_impl = stdio_aud_vfs_rewind_impl,
6e2070ea35e7 more work
William Pitcock <nenolod@atheme.org>
parents: 1978
diff changeset
262 .vfs_ftell_impl = stdio_aud_vfs_ftell_impl,
6e2070ea35e7 more work
William Pitcock <nenolod@atheme.org>
parents: 1978
diff changeset
263 .vfs_feof_impl = stdio_aud_vfs_feof_impl,
6e2070ea35e7 more work
William Pitcock <nenolod@atheme.org>
parents: 1978
diff changeset
264 .vfs_truncate_impl = stdio_aud_vfs_truncate_impl,
6e2070ea35e7 more work
William Pitcock <nenolod@atheme.org>
parents: 1978
diff changeset
265 .vfs_fsize_impl = stdio_aud_vfs_fsize_impl
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
266 };
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
267
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
268 static void init(void)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
269 {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1957
diff changeset
270 aud_vfs_register_transport(&file_const);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
271 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
272
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
273 static void cleanup(void)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
274 {
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
275 #if 0
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1957
diff changeset
276 aud_vfs_unregister_transport(&file_const);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
277 #endif
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
278 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
279
1395
761e17b23e0c added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents: 1228
diff changeset
280 DECLARE_PLUGIN(stdio, init, cleanup, NULL, NULL, NULL, NULL, NULL, NULL);