annotate libaudacious/vfs_buffer.c @ 2137:6bfa0777a57a trunk

[svn] Fixed a bug where xmms_remote_jump_to_time was called with seconds instead of milliseconds.
author jerome
date Sat, 16 Dec 2006 02:20:15 -0800
parents f18a5b617c34
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2068
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
1 /* Audacious
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
2 * Copyright (c) 2006 William Pitcock
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
3 *
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
2105
f18a5b617c34 [svn] - move to GPLv2-only. Based on my interpretation of the license, we are
nenolod
parents: 2075
diff changeset
6 * the Free Software Foundation; under version 2 of the License.
2068
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
7 *
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
11 * GNU General Public License for more details.
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
12 *
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
13 * You should have received a copy of the GNU General Public License
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
14 * along with this program; if not, write to the Free Software
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
16 * 02110-1301, USA.
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
17 */
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
18
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
19 #include <glib.h>
2075
2b93747d7b04 [svn] - build fix
yaz
parents: 2070
diff changeset
20 #include <string.h>
2068
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
21 #include "vfs.h"
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
22 #include "vfs_buffer.h"
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
23
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
24 VFSFile *
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
25 buffer_vfs_fopen_impl(const gchar * path,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
26 const gchar * mode)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
27 {
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
28 return NULL;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
29 }
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
30
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
31 gint
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
32 buffer_vfs_fclose_impl(VFSFile * file)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
33 {
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
34 g_return_val_if_fail(file != NULL, -1);
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
35
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
36 if (file->handle)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
37 g_free(file->handle);
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
38
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
39 return 0;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
40 }
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
41
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
42 size_t
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
43 buffer_vfs_fread_impl(gpointer i_ptr,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
44 size_t size,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
45 size_t nmemb,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
46 VFSFile * file)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
47 {
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
48 VFSBuffer *handle;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
49 guchar *i;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
50 size_t read = 0;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
51 guchar *ptr = (guchar *) i_ptr;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
52
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
53 if (file == NULL)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
54 return 0;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
55
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
56 handle = (VFSBuffer *) file->handle;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
57
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
58 for (i = ptr; i - ptr <= nmemb * size && i - ptr <= handle->size; i++, handle->iter++)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
59 {
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
60 *i = *handle->iter;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
61 read++;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
62 }
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
63
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
64 return (read / nmemb);
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
65 }
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
66
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
67 size_t
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
68 buffer_vfs_fwrite_impl(gconstpointer i_ptr,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
69 size_t size,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
70 size_t nmemb,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
71 VFSFile * file)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
72 {
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
73 VFSBuffer *handle;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
74 const guchar *i;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
75 size_t written = 0;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
76 const guchar *ptr = (const guchar *) i_ptr;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
77
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
78 if (file == NULL)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
79 return 0;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
80
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
81 handle = (VFSBuffer *) file->handle;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
82
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
83 for (i = ptr; (i - ptr) <= nmemb * size && (i - ptr) <= handle->size; i++, handle->iter++)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
84 {
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
85 *handle->iter = *i;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
86 written++;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
87 }
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
88
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
89 return (written / nmemb);
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
90 }
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
91
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
92 gint
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
93 buffer_vfs_getc_impl(VFSFile *stream)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
94 {
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
95 VFSBuffer *handle = (VFSBuffer *) stream->handle;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
96 gint c;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
97
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
98 c = *handle->iter;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
99 handle->iter++;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
100
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
101 return c;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
102 }
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
103
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
104 gint
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
105 buffer_vfs_ungetc_impl(gint c, VFSFile *stream)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
106 {
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
107 return -1;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
108 }
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
109
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
110 gint
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
111 buffer_vfs_fseek_impl(VFSFile * file,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
112 glong offset,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
113 gint whence)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
114 {
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
115 VFSBuffer *handle;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
116
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
117 if (file == NULL)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
118 return 0;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
119
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
120 handle = (VFSBuffer *) file->handle;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
121
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
122 switch(whence)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
123 {
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
124 case SEEK_CUR:
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
125 handle->iter = handle->iter + offset;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
126 break;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
127 case SEEK_END:
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
128 handle->iter = handle->end;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
129 break;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
130 case SEEK_SET:
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
131 default:
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
132 handle->iter = handle->data + offset;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
133 break;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
134 }
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
135
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
136 return 0;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
137 }
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
138
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
139 void
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
140 buffer_vfs_rewind_impl(VFSFile * file)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
141 {
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
142 VFSBuffer *handle;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
143
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
144 if (file == NULL)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
145 return;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
146
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
147 handle = (VFSBuffer *) file->handle;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
148
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
149 handle->iter = handle->data;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
150 }
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
151
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
152 glong
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
153 buffer_vfs_ftell_impl(VFSFile * file)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
154 {
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
155 VFSBuffer *handle;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
156
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
157 if (file == NULL)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
158 return 0;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
159
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
160 handle = (VFSBuffer *) file->handle;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
161
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
162 return handle->iter - handle->data;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
163 }
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
164
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
165 gboolean
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
166 buffer_vfs_feof_impl(VFSFile * file)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
167 {
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
168 VFSBuffer *handle;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
169
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
170 if (file == NULL)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
171 return FALSE;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
172
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
173 handle = (VFSBuffer *) file->handle;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
174
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
175 return (gboolean) (handle->iter == handle->end);
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
176 }
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
177
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
178 gint
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
179 buffer_vfs_truncate_impl(VFSFile * file, glong size)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
180 {
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
181 return 0;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
182 }
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
183
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
184 VFSConstructor buffer_const = {
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
185 NULL, // not a normal VFS class
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
186 buffer_vfs_fopen_impl,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
187 buffer_vfs_fclose_impl,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
188 buffer_vfs_fread_impl,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
189 buffer_vfs_fwrite_impl,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
190 buffer_vfs_getc_impl,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
191 buffer_vfs_ungetc_impl,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
192 buffer_vfs_fseek_impl,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
193 buffer_vfs_rewind_impl,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
194 buffer_vfs_ftell_impl,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
195 buffer_vfs_feof_impl,
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
196 buffer_vfs_truncate_impl
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
197 };
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
198
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
199 VFSFile *
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
200 vfs_buffer_new(gpointer data, gsize size)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
201 {
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
202 VFSFile *handle;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
203 VFSBuffer *buffer;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
204
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
205 g_return_val_if_fail(data != NULL, NULL);
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
206 g_return_val_if_fail(size > 0, NULL);
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
207
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
208 handle = g_new0(VFSFile, 1);
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
209 handle->uri == NULL;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
210
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
211 buffer = g_new0(VFSBuffer, 1);
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
212 buffer->data = data;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
213 buffer->iter = data;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
214 buffer->end = data + size;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
215 buffer->size = size;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
216
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
217 handle->handle = buffer;
2069
5bc48557acbb [svn] - make sure handle->base is a constpointer.
nenolod
parents: 2068
diff changeset
218 handle->base = &buffer_const;
2068
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
219
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
220 return handle;
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
221 }
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
222
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
223 VFSFile *
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
224 vfs_buffer_new_from_string(gchar *str)
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
225 {
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
226 g_return_val_if_fail(str != NULL, NULL);
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
227
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
228 return vfs_buffer_new(str, strlen(str));
31b5c59ed31b [svn] - add VFSBuffer, equivilant to fmemopen().
nenolod
parents:
diff changeset
229 }