annotate src/audacious/vfs_common.c @ 4266:2b7a74fce100

Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
author stefano@zanga
date Sun, 10 Feb 2008 12:31:44 +0100
parents d9870d3e9550
children 694ce1a806f8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
1 /* This program is free software; you can redistribute it and/or modify
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
2 * it under the terms of the GNU General Public License as published by
3123
f1c756f39e6c Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents: 2424
diff changeset
3 * the Free Software Foundation; under version 3 of the License.
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
4 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
5 * This program is distributed in the hope that it will be useful,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
6 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
8 * GNU General Public License for more details.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
9 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
10 * You should have received a copy of the GNU General Public License
3123
f1c756f39e6c Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents: 2424
diff changeset
11 * along with this program. If not, see <http://www.gnu.org/licenses>.
f1c756f39e6c Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents: 2424
diff changeset
12 *
f1c756f39e6c Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents: 2424
diff changeset
13 * The Audacious team does not consider modular code linking to
f1c756f39e6c Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents: 2424
diff changeset
14 * Audacious or using our public API to be a derived work.
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
15 */
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
16
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
17 #include "vfs.h"
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
18 #include <string.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
19 #include <stdlib.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
20 #include <glib/gprintf.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
21
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
22 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
23 * vfs_fputc:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
24 * @c: A character to write to the stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
25 * @stream: A #VFSFile object representing the stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
26 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
27 * Writes a character to a stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
28 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
29 * Return value: The character on success, or EOF.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
30 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
31 gint vfs_fputc(gint c, VFSFile *stream)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
32 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
33 guchar uc = (guchar) c;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
34
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
35 if (! vfs_fwrite(&uc, 1, 1, stream)) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
36 return EOF;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
37 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
38
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
39 return uc;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
40 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
41
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
42 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
43 * vfs_fgets:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
44 * @s: A buffer to put the string in.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
45 * @n: The amount of characters to read.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
46 * @stream: A #VFSFile object representing the stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
47 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
48 * Reads a set of characters from a stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
49 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
50 * Return value: The string on success, or NULL.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
51 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
52 gchar *vfs_fgets(gchar *s, gint n, VFSFile *stream)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
53 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
54 gint c;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
55 register gchar *p;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
56
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
57 if(n<=0) return NULL;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
58
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
59 p = s;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
60
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
61 while (--n) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
62 if ((c = vfs_getc(stream))== EOF) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
63 break;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
64 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
65 if ((*p++ = c) == '\n') {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
66 break;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
67 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
68 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
69 if (p > s) {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
70 *p = 0;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
71 return s;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
72 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
73
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
74 return NULL;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
75 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
76
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
77 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
78 * vfs_fputc:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
79 * @s: A string to write to the stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
80 * @stream: A #VFSFile object representing the stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
81 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
82 * Writes a string to a VFS stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
83 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
84 * Return value: The amount of bytes written.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
85 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
86 int vfs_fputs(const gchar *s, VFSFile *stream)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
87 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
88 size_t n = strlen(s);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
89
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
90 return ((vfs_fwrite(s, 1, n, stream) == n) ? n : EOF);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
91 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
92
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
93 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
94 * vfs_vfprintf:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
95 * @stream: A #VFSFile object representing the stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
96 * @format: A printf-style format string.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
97 * @args: A va_list of args to use.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
98 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
99 * Writes a formatted string to a VFS stream via a va_list of args.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
100 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
101 * Return value: The amount of bytes written.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
102 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
103 int vfs_vfprintf(VFSFile *stream, gchar const *format, va_list args)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
104 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
105 gchar *string;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
106 gint rv = g_vasprintf(&string, format, args);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
107 if (rv<0) return rv;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
108 rv = vfs_fputs(string, stream);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
109 free (string);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
110 return rv;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
111 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
112
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
113 /**
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
114 * vfs_fprintf:
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
115 * @stream: A #VFSFile object representing the stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
116 * @format: A printf-style format string.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
117 * @...: A list of args to use.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
118 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
119 * Writes a formatted string to a VFS stream.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
120 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
121 * Return value: The amount of bytes written.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
122 **/
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
123 int vfs_fprintf(VFSFile *stream, gchar const *format, ...)
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
124 {
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
125 va_list arg;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
126 gint rv;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
127
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
128 va_start(arg, format);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
129 rv = vfs_vfprintf(stream, format, arg);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
130 va_end(arg);
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
131
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
132 return rv;
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
133 }
2424
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
134
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
135 /**
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
136 * vfs_file_get_contents
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
137 * @filename: the filename to read in
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
138 * @buf: pointer to pointer of buffer
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
139 * @sz: pointer to integer that is the size
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
140 **/
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
141 void
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
142 vfs_file_get_contents(const gchar *filename, gchar **buf, gsize *size)
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
143 {
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
144 VFSFile *fd;
4129
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
145 size_t filled_size = 0;
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
146 size_t buf_size = 4096;
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
147 gchar *ptr;
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
148
2424
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
149 fd = vfs_fopen(filename, "rb");
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
150
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
151 if (fd == NULL)
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
152 return;
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
153
4129
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
154 if ( vfs_fseek(fd, 0, SEEK_END) == 0) { // seeking supported by VFS backend
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
155 *size = vfs_ftell(fd);
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
156
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
157 *buf = g_new(gchar, *size);
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
158
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
159 if (*buf == NULL)
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
160 goto close_handle;
2424
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
161
4129
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
162 vfs_fseek(fd, 0, SEEK_SET);
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
163 vfs_fread(*buf, 1, *size, fd);
2424
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
164
4129
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
165 goto close_handle;
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
166 }
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
167
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
168
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
169 *buf = g_new(gchar, buf_size);
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
170
2424
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
171 if (*buf == NULL)
4129
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
172 goto close_handle;
2424
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
173
4129
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
174 ptr=*buf;
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
175 while ( 1 ) {
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
176 size_t read_size = vfs_fread(ptr, 1, buf_size - filled_size, fd);
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
177 if ( read_size == 0 ) break;
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
178
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
179 filled_size+=read_size;
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
180 ptr+=read_size;
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
181
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
182 if ( filled_size == buf_size ) {
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
183 buf_size+=4096;
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
184
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
185 *buf = g_realloc(*buf, buf_size);
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
186
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
187 if ( *buf == NULL )
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
188 goto close_handle;
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
189
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
190 ptr=*buf + filled_size;
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
191 }
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
192 }
2424
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
193
4129
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
194 *size = filled_size;
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
195
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
196 close_handle:
d9870d3e9550 Fix downloading of dynamically generated content with vfs_get_file_contents(). (Bugzilla #46)
Maciej Grela <thermal@o2.pl>
parents: 3123
diff changeset
197 vfs_fclose(fd);
2424
3e3d34173207 [svn] - vfs_get_file_contents() implementation.
nenolod
parents: 2313
diff changeset
198 }