annotate libaudacious/vfs_buffer.c @ 2085:472be23d11a1 trunk

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