22 #include <glib/gprintf.h>
46 unsigned char uc = (
unsigned char) c;
68 if (n <= 0)
return NULL;
76 if ((*p++ = c) ==
'\n') {
99 return ((
vfs_fwrite(s, 1, n, stream) == n) ? n : EOF);
113 int rv = g_vasprintf(&
string, format, args);
114 if (rv < 0)
return rv;
133 va_start(arg, format);
155 gsize filled_size = 0, buf_size = 4096;
163 * buf = g_malloc (* size);
164 * size =
vfs_fread (* buf, 1, * size, fd);
168 if ((*buf = g_malloc(buf_size)) ==
NULL)
173 gsize read_size =
vfs_fread(ptr, 1, buf_size - filled_size, fd);
174 if (read_size == 0)
break;
176 filled_size += read_size;
179 if (filled_size == buf_size) {
182 *buf = g_realloc(*buf, buf_size);
187 ptr = (
unsigned char *) (* buf) + filled_size;
209 if (
vfs_fread(&tmp,
sizeof(tmp), 1, stream) != 1)
211 *value = GUINT16_FROM_LE(tmp);
225 if (
vfs_fread(&tmp,
sizeof(tmp), 1, stream) != 1)
227 *value = GUINT32_FROM_LE(tmp);
241 if (
vfs_fread(&tmp,
sizeof(tmp), 1, stream) != 1)
243 *value = GUINT64_FROM_LE(tmp);
258 if (
vfs_fread(&tmp,
sizeof(tmp), 1, stream) != 1)
260 *value = GUINT16_FROM_BE(tmp);
274 if (
vfs_fread(&tmp,
sizeof(tmp), 1, stream) != 1)
276 *value = GUINT32_FROM_BE(tmp);
290 if (
vfs_fread(&tmp,
sizeof(tmp), 1, stream) != 1)
292 *value = GUINT64_FROM_BE(tmp);
306 uint16_t tmp = GUINT16_TO_LE(value);
307 return vfs_fwrite(&tmp,
sizeof(tmp), 1, stream) == 1;
320 uint32_t tmp = GUINT32_TO_LE(value);
321 return vfs_fwrite(&tmp,
sizeof(tmp), 1, stream) == 1;
334 uint64_t tmp = GUINT64_TO_LE(value);
335 return vfs_fwrite(&tmp,
sizeof(tmp), 1, stream) == 1;
348 uint16_t tmp = GUINT16_TO_BE(value);
349 return vfs_fwrite(&tmp,
sizeof(tmp), 1, stream) == 1;
362 uint32_t tmp = GUINT32_TO_BE(value);
363 return vfs_fwrite(&tmp,
sizeof(tmp), 1, stream) == 1;
376 uint64_t tmp = GUINT64_TO_BE(value);
377 return vfs_fwrite(&tmp,
sizeof(tmp), 1, stream) == 1;
EXPORT int64_t vfs_fwrite(const void *ptr, int64_t size, int64_t nmemb, VFSFile *file)
Writes to a VFS stream.
EXPORT int vfs_vfprintf(VFSFile *stream, char const *format, va_list args)
Writes a formatted string to a VFS stream via a va_list of args.
bool_t vfs_fget_le64(uint64_t *value, VFSFile *stream) WARN_RETURN
Reads an unsigned 64-bit Little Endian value from the stream into native endian format.
bool_t vfs_fget_le32(uint32_t *value, VFSFile *stream) WARN_RETURN
Reads an unsigned 32-bit Little Endian value from the stream into native endian format.
bool_t vfs_fget_be32(uint32_t *value, VFSFile *stream) WARN_RETURN
Reads an unsigned 32-bit Big Endian value from the stream into native endian format.
bool_t vfs_fput_be32(uint32_t value, VFSFile *stream) WARN_RETURN
Writes an unsigned 32-bit native endian value into the stream as a Big Endian value.
bool_t vfs_fput_be16(uint16_t value, VFSFile *stream) WARN_RETURN
Writes an unsigned 16-bit native endian value into the stream as a Big Endian value.
bool_t vfs_fget_le16(uint16_t *value, VFSFile *stream) WARN_RETURN
Reads an unsigned 16-bit Little Endian value from the stream into native endian format.
Main API header for accessing Audacious VFS functionality.
EXPORT int vfs_fclose(VFSFile *file)
Closes a VFS stream and destroys a VFSFile object.
bool_t vfs_fget_be16(uint16_t *value, VFSFile *stream) WARN_RETURN
Reads an unsigned 16-bit Big Endian value from the stream into native endian format.
bool_t vfs_fput_le16(uint16_t value, VFSFile *stream) WARN_RETURN
Writes an unsigned 16-bit native endian value into the stream as a Little Endian value.
EXPORT int vfs_fputs(const char *s, VFSFile *stream)
Writes a string to a VFS stream.
EXPORT int vfs_fputc(int c, VFSFile *stream)
Writes a character to a stream.
bool_t vfs_fput_le64(uint64_t value, VFSFile *stream) WARN_RETURN
Writes an unsigned 64-bit native endian value into the stream as a Big Endian value.
EXPORT int64_t vfs_fread(void *ptr, int64_t size, int64_t nmemb, VFSFile *file)
Reads from a VFS stream.
bool_t vfs_fput_be64(uint64_t value, VFSFile *stream) WARN_RETURN
Writes an unsigned 64-bit native endian value into the stream as a Big Endian value.
EXPORT VFSFile * vfs_fopen(const char *path, const char *mode)
Opens a stream from a VFS transport using one of the registered VFSConstructor handlers.
bool_t vfs_fput_le32(uint32_t value, VFSFile *stream) WARN_RETURN
Writes an unsigned 32-bit native endian value into the stream as a Big Endian value.
void vfs_file_get_contents(const char *filename, void **buf, int64_t *size)
Gets contents of the file into a buffer.
EXPORT int vfs_getc(VFSFile *file)
Reads a character from a VFS stream.
char * vfs_fgets(char *s, int n, VFSFile *stream) WARN_RETURN
Reads a string of characters from a stream, ending in newline or EOF.
EXPORT int64_t vfs_fsize(VFSFile *file)
Returns size of the file.
bool_t vfs_fget_be64(uint64_t *value, VFSFile *stream) WARN_RETURN
Reads an unsigned 64-bit Big Endian value from the stream into native endian format.
int vfs_fprintf(VFSFile *stream, char const *format,...) __attribute__((__format__(__printf__