Mercurial > audlegacy
annotate src/audacious/vfs_common.c @ 4392:9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 30 Mar 2008 00:58:02 +0200 |
parents | 694ce1a806f8 |
children |
rev | line source |
---|---|
2313 | 1 /* This program is free software; you can redistribute it and/or modify |
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 | 4 * |
5 * This program is distributed in the hope that it will be useful, | |
6 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
8 * GNU General Public License for more details. | |
9 * | |
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 | 15 */ |
16 | |
17 #include "vfs.h" | |
18 #include <string.h> | |
19 #include <stdlib.h> | |
20 #include <glib/gprintf.h> | |
21 | |
22 /** | |
23 * vfs_fputc: | |
24 * @c: A character to write to the stream. | |
25 * @stream: A #VFSFile object representing the stream. | |
26 * | |
27 * Writes a character to a stream. | |
28 * | |
29 * Return value: The character on success, or EOF. | |
30 **/ | |
31 gint vfs_fputc(gint c, VFSFile *stream) | |
32 { | |
33 guchar uc = (guchar) c; | |
34 | |
35 if (! vfs_fwrite(&uc, 1, 1, stream)) { | |
36 return EOF; | |
37 } | |
38 | |
39 return uc; | |
40 } | |
41 | |
42 /** | |
43 * vfs_fgets: | |
44 * @s: A buffer to put the string in. | |
45 * @n: The amount of characters to read. | |
46 * @stream: A #VFSFile object representing the stream. | |
47 * | |
48 * Reads a set of characters from a stream. | |
49 * | |
50 * Return value: The string on success, or NULL. | |
51 **/ | |
52 gchar *vfs_fgets(gchar *s, gint n, VFSFile *stream) | |
53 { | |
54 gint c; | |
55 register gchar *p; | |
56 | |
57 if(n<=0) return NULL; | |
58 | |
59 p = s; | |
60 | |
61 while (--n) { | |
62 if ((c = vfs_getc(stream))== EOF) { | |
63 break; | |
64 } | |
65 if ((*p++ = c) == '\n') { | |
66 break; | |
67 } | |
68 } | |
69 if (p > s) { | |
70 *p = 0; | |
71 return s; | |
72 } | |
73 | |
74 return NULL; | |
75 } | |
76 | |
77 /** | |
78 * vfs_fputc: | |
79 * @s: A string to write to the stream. | |
80 * @stream: A #VFSFile object representing the stream. | |
81 * | |
82 * Writes a string to a VFS stream. | |
83 * | |
84 * Return value: The amount of bytes written. | |
85 **/ | |
4390
694ce1a806f8
int -> gint for uniformity.
Matti Hamalainen <ccr@tnsp.org>
parents:
4129
diff
changeset
|
86 gint vfs_fputs(const gchar *s, VFSFile *stream) |
2313 | 87 { |
88 size_t n = strlen(s); | |
89 | |
90 return ((vfs_fwrite(s, 1, n, stream) == n) ? n : EOF); | |
91 } | |
92 | |
93 /** | |
94 * vfs_vfprintf: | |
95 * @stream: A #VFSFile object representing the stream. | |
96 * @format: A printf-style format string. | |
97 * @args: A va_list of args to use. | |
98 * | |
99 * Writes a formatted string to a VFS stream via a va_list of args. | |
100 * | |
101 * Return value: The amount of bytes written. | |
102 **/ | |
4390
694ce1a806f8
int -> gint for uniformity.
Matti Hamalainen <ccr@tnsp.org>
parents:
4129
diff
changeset
|
103 gint vfs_vfprintf(VFSFile *stream, gchar const *format, va_list args) |
2313 | 104 { |
105 gchar *string; | |
106 gint rv = g_vasprintf(&string, format, args); | |
107 if (rv<0) return rv; | |
108 rv = vfs_fputs(string, stream); | |
109 free (string); | |
110 return rv; | |
111 } | |
112 | |
113 /** | |
114 * vfs_fprintf: | |
115 * @stream: A #VFSFile object representing the stream. | |
116 * @format: A printf-style format string. | |
117 * @...: A list of args to use. | |
118 * | |
119 * Writes a formatted string to a VFS stream. | |
120 * | |
121 * Return value: The amount of bytes written. | |
122 **/ | |
4390
694ce1a806f8
int -> gint for uniformity.
Matti Hamalainen <ccr@tnsp.org>
parents:
4129
diff
changeset
|
123 gint vfs_fprintf(VFSFile *stream, gchar const *format, ...) |
2313 | 124 { |
125 va_list arg; | |
126 gint rv; | |
127 | |
128 va_start(arg, format); | |
129 rv = vfs_vfprintf(stream, format, arg); | |
130 va_end(arg); | |
131 | |
132 return rv; | |
133 } | |
2424 | 134 |
135 /** | |
136 * vfs_file_get_contents | |
137 * @filename: the filename to read in | |
138 * @buf: pointer to pointer of buffer | |
139 * @sz: pointer to integer that is the size | |
140 **/ | |
141 void | |
142 vfs_file_get_contents(const gchar *filename, gchar **buf, gsize *size) | |
143 { | |
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 | 149 fd = vfs_fopen(filename, "rb"); |
150 | |
151 if (fd == NULL) | |
152 return; | |
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 | 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 | 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 | 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 | 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 | 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 | 198 } |
4392
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
199 |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
200 |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
201 /** |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
202 * vfs_fget_le16: |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
203 * @value: Pointer to the variable to read the value into. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
204 * @stream: A #VFSFile object representing the stream. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
205 * |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
206 * Reads an unsigned 16-bit Little Endian value from the stream into native endian format. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
207 * |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
208 * Return value: TRUE if read was succesful, FALSE if there was an error. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
209 **/ |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
210 gboolean vfs_fget_le16(guint16 *value, VFSFile *stream) |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
211 { |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
212 guint16 tmp; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
213 if (vfs_fread(&tmp, sizeof(guint16), 1, stream) != 1) |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
214 return FALSE; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
215 *value = GUINT16_FROM_LE(tmp); |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
216 return TRUE; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
217 } |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
218 |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
219 /** |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
220 * vfs_fget_le32: |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
221 * @value: Pointer to the variable to read the value into. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
222 * @stream: A #VFSFile object representing the stream. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
223 * |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
224 * Reads an unsigned 32-bit Little Endian value from the stream into native endian format. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
225 * |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
226 * Return value: TRUE if read was succesful, FALSE if there was an error. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
227 **/ |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
228 gboolean vfs_fget_le32(guint32 *value, VFSFile *stream) |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
229 { |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
230 guint32 tmp; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
231 if (vfs_fread(&tmp, sizeof(guint32), 1, stream) != 1) |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
232 return FALSE; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
233 *value = GUINT32_FROM_LE(tmp); |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
234 return TRUE; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
235 } |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
236 |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
237 /** |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
238 * vfs_fget_le64: |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
239 * @value: Pointer to the variable to read the value into. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
240 * @stream: A #VFSFile object representing the stream. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
241 * |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
242 * Reads an unsigned 64-bit Little Endian value from the stream into native endian format. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
243 * |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
244 * Return value: TRUE if read was succesful, FALSE if there was an error. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
245 **/ |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
246 gboolean vfs_fget_le64(guint64 *value, VFSFile *stream) |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
247 { |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
248 guint64 tmp; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
249 if (vfs_fread(&tmp, sizeof(guint64), 1, stream) != 1) |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
250 return FALSE; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
251 *value = GUINT64_FROM_LE(tmp); |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
252 return TRUE; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
253 } |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
254 |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
255 |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
256 /** |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
257 * vfs_fget_be16: |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
258 * @value: Pointer to the variable to read the value into. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
259 * @stream: A #VFSFile object representing the stream. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
260 * |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
261 * Reads an unsigned 16-bit Big Endian value from the stream into native endian format. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
262 * |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
263 * Return value: TRUE if read was succesful, FALSE if there was an error. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
264 **/ |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
265 gboolean vfs_fget_be16(guint16 *value, VFSFile *stream) |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
266 { |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
267 guint16 tmp; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
268 if (vfs_fread(&tmp, sizeof(guint16), 1, stream) != 1) |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
269 return FALSE; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
270 *value = GUINT16_FROM_BE(tmp); |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
271 return TRUE; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
272 } |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
273 |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
274 /** |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
275 * vfs_fget_be32: |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
276 * @value: Pointer to the variable to read the value into. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
277 * @stream: A #VFSFile object representing the stream. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
278 * |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
279 * Reads an unsigned 32-bit Big Endian value from the stream into native endian format. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
280 * |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
281 * Return value: TRUE if read was succesful, FALSE if there was an error. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
282 **/ |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
283 gboolean vfs_fget_be32(guint32 *value, VFSFile *stream) |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
284 { |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
285 guint32 tmp; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
286 if (vfs_fread(&tmp, sizeof(guint32), 1, stream) != 1) |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
287 return FALSE; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
288 *value = GUINT32_FROM_BE(tmp); |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
289 return TRUE; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
290 } |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
291 |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
292 /** |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
293 * vfs_fget_be64: |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
294 * @value: Pointer to the variable to read the value into. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
295 * @stream: A #VFSFile object representing the stream. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
296 * |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
297 * Reads an unsigned 64-bit Big Endian value from the stream into native endian format. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
298 * |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
299 * Return value: TRUE if read was succesful, FALSE if there was an error. |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
300 **/ |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
301 gboolean vfs_fget_be64(guint64 *value, VFSFile *stream) |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
302 { |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
303 guint64 tmp; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
304 if (vfs_fread(&tmp, sizeof(guint64), 1, stream) != 1) |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
305 return FALSE; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
306 *value = GUINT64_FROM_BE(tmp); |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
307 return TRUE; |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
308 } |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
309 |
9d5e6bfca672
Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats)
Matti Hamalainen <ccr@tnsp.org>
parents:
4390
diff
changeset
|
310 |