annotate src/stdio/stdio.c @ 965:f1642ee1115c trunk

[svn] - Implement vfs_fsize() for stdio - Implement dummys for curl/mms/smb
author ertzing
date Fri, 20 Apr 2007 06:50:15 -0700
parents 1d81ea250dce
children 183d03932c9e
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
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
19 #include <audacious/vfs.h>
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
20 #include <audacious/plugin.h>
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
21 #include <stdio.h>
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
22
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
23 #include <unistd.h>
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
24 #include <sys/stat.h>
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
25 #include <sys/types.h>
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
26
500
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
27 #include <string.h>
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
28
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
29 static gchar *
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
30 vfs_stdio_urldecode_path(const gchar * encoded_path)
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
31 {
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
32 const gchar *cur, *ext;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
33 gchar *path, *tmp;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
34 gint realchar;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
35
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
36 if (!encoded_path)
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
37 return NULL;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
38
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
39 if (!str_has_prefix_nocase(encoded_path, "file:"))
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
40 return NULL;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
41
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
42 cur = encoded_path + 5;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
43
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
44 if (str_has_prefix_nocase(cur, "//localhost"))
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
45 cur += 11;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
46
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
47 if (*cur == '/')
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
48 while (cur[1] == '/')
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
49 cur++;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
50
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
51 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
52
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
53 while ((ext = strchr(cur, '%')) != NULL) {
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
54 strncat(tmp, cur, ext - cur);
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
55 ext++;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
56 cur = ext + 2;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
57 if (!sscanf(ext, "%2x", &realchar)) {
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
58 /* 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
59 * 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
60 * and drop. */
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
61 realchar = '%';
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
62 cur -= 2;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
63 }
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
64 tmp[strlen(tmp)] = realchar;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
65 }
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 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
68 g_free(tmp);
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
69 return path;
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
70 }
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
71
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
72 VFSFile *
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
73 stdio_vfs_fopen_impl(const gchar * path,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
74 const gchar * mode)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
75 {
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
76 VFSFile *file;
500
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
77 gchar *decpath;
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
78
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
79 if (!path || !mode)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
80 return NULL;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
81
500
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
82 decpath = vfs_stdio_urldecode_path(path);
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
83
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
84 file = g_new(VFSFile, 1);
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
85
500
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
86 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
87
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
88 if (decpath != NULL)
1d81ea250dce [svn] - URIs are now passed naked instead of mangled by the VFS subsystem.
nenolod
parents: 326
diff changeset
89 g_free(decpath);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
90
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
91 if (file->handle == NULL) {
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
92 g_free(file);
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
93 file = NULL;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
94 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
95
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
96 return file;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
97 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
98
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
99 gint
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
100 stdio_vfs_fclose_impl(VFSFile * file)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
101 {
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
102 gint ret = 0;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
103
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
104 if (file == NULL)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
105 return -1;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
106
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
107 if (file->handle)
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
108 {
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
109 FILE *handle = (FILE *) file->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
110
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
111 if (fclose(handle) != 0)
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
112 ret = -1;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
113 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
114
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
115 return ret;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
116 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
117
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
118 size_t
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
119 stdio_vfs_fread_impl(gpointer ptr,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
120 size_t size,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
121 size_t nmemb,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
122 VFSFile * file)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
123 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
124 FILE *handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
125
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
126 if (file == NULL)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
127 return 0;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
128
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
129 handle = (FILE *) file->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
130
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
131 return fread(ptr, size, nmemb, handle);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
132 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
133
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
134 size_t
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
135 stdio_vfs_fwrite_impl(gconstpointer ptr,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
136 size_t size,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
137 size_t nmemb,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
138 VFSFile * file)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
139 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
140 FILE *handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
141
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
142 if (file == NULL)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
143 return 0;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
144
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
145 handle = (FILE *) file->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
146
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
147 return fwrite(ptr, size, nmemb, handle);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
148 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
149
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
150 gint
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
151 stdio_vfs_getc_impl(VFSFile *stream)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
152 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
153 FILE *handle = (FILE *) stream->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
154
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
155 return getc( handle );
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
156 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
157
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
158 gint
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
159 stdio_vfs_ungetc_impl(gint c, VFSFile *stream)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
160 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
161 FILE *handle = (FILE *) stream->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
162
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
163 return ungetc( c , handle );
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
164 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
165
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
166 gint
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
167 stdio_vfs_fseek_impl(VFSFile * file,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
168 glong offset,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
169 gint whence)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
170 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
171 FILE *handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
172
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
173 if (file == NULL)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
174 return 0;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
175
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
176 handle = (FILE *) file->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
177
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
178 return fseek(handle, offset, whence);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
179 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
180
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
181 void
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
182 stdio_vfs_rewind_impl(VFSFile * file)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
183 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
184 FILE *handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
185
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
186 if (file == NULL)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
187 return;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
188
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
189 handle = (FILE *) file->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
190
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
191 rewind(handle);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
192 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
193
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
194 glong
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
195 stdio_vfs_ftell_impl(VFSFile * file)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
196 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
197 FILE *handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
198
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
199 if (file == NULL)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
200 return 0;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
201
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
202 handle = (FILE *) file->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
203
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
204 return ftell(handle);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
205 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
206
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
207 gboolean
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
208 stdio_vfs_feof_impl(VFSFile * file)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
209 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
210 FILE *handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
211
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
212 if (file == NULL)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
213 return FALSE;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
214
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
215 handle = (FILE *) file->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
216
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
217 return (gboolean) feof(handle);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
218 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
219
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
220 gint
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
221 stdio_vfs_truncate_impl(VFSFile * file, glong size)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
222 {
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
223 FILE *handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
224
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
225 if (file == NULL)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
226 return -1;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
227
326
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
228 handle = (FILE *) file->handle;
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
229
90a843d02970 [svn] - some OSes use macros for some f*() functions, therefore make sure we
nenolod
parents: 306
diff changeset
230 return ftruncate(fileno(handle), size);
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
231 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
232
965
ertzing
parents: 500
diff changeset
233 off_t
ertzing
parents: 500
diff changeset
234 stdio_vfs_fsize_impl(VFSFile * file)
ertzing
parents: 500
diff changeset
235 {
ertzing
parents: 500
diff changeset
236 FILE *handle;
ertzing
parents: 500
diff changeset
237 struct stat s;
ertzing
parents: 500
diff changeset
238
ertzing
parents: 500
diff changeset
239 if (file == NULL)
ertzing
parents: 500
diff changeset
240 return -1;
ertzing
parents: 500
diff changeset
241
ertzing
parents: 500
diff changeset
242 handle = (FILE *) file->handle;
ertzing
parents: 500
diff changeset
243
ertzing
parents: 500
diff changeset
244 if (-1 == fstat(fileno(handle), &s))
ertzing
parents: 500
diff changeset
245 return -1;
ertzing
parents: 500
diff changeset
246
ertzing
parents: 500
diff changeset
247 return s.st_size;
ertzing
parents: 500
diff changeset
248 }
ertzing
parents: 500
diff changeset
249
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
250 VFSConstructor file_const = {
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
251 "file://",
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
252 stdio_vfs_fopen_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
253 stdio_vfs_fclose_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
254 stdio_vfs_fread_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
255 stdio_vfs_fwrite_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
256 stdio_vfs_getc_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
257 stdio_vfs_ungetc_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
258 stdio_vfs_fseek_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
259 stdio_vfs_rewind_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
260 stdio_vfs_ftell_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
261 stdio_vfs_feof_impl,
965
ertzing
parents: 500
diff changeset
262 stdio_vfs_truncate_impl,
ertzing
parents: 500
diff changeset
263 stdio_vfs_fsize_impl
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
264 };
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
265
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
266 VFSConstructor default_const = {
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
267 "/",
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
268 stdio_vfs_fopen_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
269 stdio_vfs_fclose_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
270 stdio_vfs_fread_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
271 stdio_vfs_fwrite_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
272 stdio_vfs_getc_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
273 stdio_vfs_ungetc_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
274 stdio_vfs_fseek_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
275 stdio_vfs_rewind_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
276 stdio_vfs_ftell_impl,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
277 stdio_vfs_feof_impl,
965
ertzing
parents: 500
diff changeset
278 stdio_vfs_truncate_impl,
ertzing
parents: 500
diff changeset
279 stdio_vfs_fsize_impl
306
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
280 };
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
281
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
282 static void init(void)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
283 {
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
284 vfs_register_transport(&default_const);
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
285 vfs_register_transport(&file_const);
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
286 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
287
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
288 static void cleanup(void)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
289 {
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
290 #if 0
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
291 vfs_unregister_transport(&default_const);
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
292 vfs_unregister_transport(&file_const);
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
293 #endif
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
294 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
295
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
296 LowlevelPlugin llp_stdio = {
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
297 NULL,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
298 NULL,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
299 "file:// URI Transport",
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
300 init,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
301 cleanup,
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
302 };
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
303
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
304 LowlevelPlugin *get_lplugin_info(void)
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
305 {
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
306 return &llp_stdio;
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
307 }
b47f02042530 [svn] - pluginize the transport layer.
nenolod
parents:
diff changeset
308