Mercurial > audlegacy
changeset 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 | a9c8efbfd4c2 |
children | 4bbc90cc4c42 |
files | src/audacious/plugin.h src/audacious/vfs.h src/audacious/vfs_common.c |
diffstat | 3 files changed, 133 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/audacious/plugin.h Sun Mar 30 00:51:14 2008 +0200 +++ b/src/audacious/plugin.h Sun Mar 30 00:58:02 2008 +0200 @@ -652,6 +652,13 @@ void (*event_queue)(const gchar *name, gpointer user_data); + /* VFS endianess helper functions */ + gboolean (*vfs_fget_le16)(guint16 *value, VFSFile *stream); + gboolean (*vfs_fget_le32)(guint32 *value, VFSFile *stream); + gboolean (*vfs_fget_le64)(guint64 *value, VFSFile *stream); + gboolean (*vfs_fget_be16)(guint16 *value, VFSFile *stream); + gboolean (*vfs_fget_be32)(guint32 *value, VFSFile *stream); + gboolean (*vfs_fget_be64)(guint64 *value, VFSFile *stream); }; /* Convenience macros for accessing the public API. */ @@ -685,6 +692,13 @@ #define aud_vfs_buffered_file_new_from_uri _audvt->vfs_buffered_file_new_from_uri #define aud_vfs_buffered_file_release_live_fd _audvt->vfs_buffered_file_release_live_fd +#define aud_vfs_fget_le16 _audvt->vfs_fget_le16 +#define aud_vfs_fget_le32 _audvt->vfs_fget_le32 +#define aud_vfs_fget_le64 _audvt->vfs_fget_le64 +#define aud_vfs_fget_be16 _audvt->vfs_fget_be16 +#define aud_vfs_fget_be32 _audvt->vfs_fget_be32 +#define aud_vfs_fget_be64 _audvt->vfs_fget_be64 + /* XXX: deprecation warnings */ #define bmp_cfg_db_open _audvt->cfg_db_open #define bmp_cfg_db_close _audvt->cfg_db_close
--- a/src/audacious/vfs.h Sun Mar 30 00:51:14 2008 +0200 +++ b/src/audacious/vfs.h Sun Mar 30 00:58:02 2008 +0200 @@ -136,6 +136,13 @@ extern gboolean vfs_is_streaming(VFSFile *file); +extern gboolean vfs_fget_le16(guint16 *value, VFSFile *stream); +extern gboolean vfs_fget_le32(guint32 *value, VFSFile *stream); +extern gboolean vfs_fget_le64(guint64 *value, VFSFile *stream); +extern gboolean vfs_fget_be16(guint16 *value, VFSFile *stream); +extern gboolean vfs_fget_be32(guint32 *value, VFSFile *stream); +extern gboolean vfs_fget_be64(guint64 *value, VFSFile *stream); + G_END_DECLS #endif /* VFS_H */
--- a/src/audacious/vfs_common.c Sun Mar 30 00:51:14 2008 +0200 +++ b/src/audacious/vfs_common.c Sun Mar 30 00:58:02 2008 +0200 @@ -196,3 +196,115 @@ close_handle: vfs_fclose(fd); } + + +/** + * vfs_fget_le16: + * @value: Pointer to the variable to read the value into. + * @stream: A #VFSFile object representing the stream. + * + * Reads an unsigned 16-bit Little Endian value from the stream into native endian format. + * + * Return value: TRUE if read was succesful, FALSE if there was an error. + **/ +gboolean vfs_fget_le16(guint16 *value, VFSFile *stream) +{ + guint16 tmp; + if (vfs_fread(&tmp, sizeof(guint16), 1, stream) != 1) + return FALSE; + *value = GUINT16_FROM_LE(tmp); + return TRUE; +} + +/** + * vfs_fget_le32: + * @value: Pointer to the variable to read the value into. + * @stream: A #VFSFile object representing the stream. + * + * Reads an unsigned 32-bit Little Endian value from the stream into native endian format. + * + * Return value: TRUE if read was succesful, FALSE if there was an error. + **/ +gboolean vfs_fget_le32(guint32 *value, VFSFile *stream) +{ + guint32 tmp; + if (vfs_fread(&tmp, sizeof(guint32), 1, stream) != 1) + return FALSE; + *value = GUINT32_FROM_LE(tmp); + return TRUE; +} + +/** + * vfs_fget_le64: + * @value: Pointer to the variable to read the value into. + * @stream: A #VFSFile object representing the stream. + * + * Reads an unsigned 64-bit Little Endian value from the stream into native endian format. + * + * Return value: TRUE if read was succesful, FALSE if there was an error. + **/ +gboolean vfs_fget_le64(guint64 *value, VFSFile *stream) +{ + guint64 tmp; + if (vfs_fread(&tmp, sizeof(guint64), 1, stream) != 1) + return FALSE; + *value = GUINT64_FROM_LE(tmp); + return TRUE; +} + + +/** + * vfs_fget_be16: + * @value: Pointer to the variable to read the value into. + * @stream: A #VFSFile object representing the stream. + * + * Reads an unsigned 16-bit Big Endian value from the stream into native endian format. + * + * Return value: TRUE if read was succesful, FALSE if there was an error. + **/ +gboolean vfs_fget_be16(guint16 *value, VFSFile *stream) +{ + guint16 tmp; + if (vfs_fread(&tmp, sizeof(guint16), 1, stream) != 1) + return FALSE; + *value = GUINT16_FROM_BE(tmp); + return TRUE; +} + +/** + * vfs_fget_be32: + * @value: Pointer to the variable to read the value into. + * @stream: A #VFSFile object representing the stream. + * + * Reads an unsigned 32-bit Big Endian value from the stream into native endian format. + * + * Return value: TRUE if read was succesful, FALSE if there was an error. + **/ +gboolean vfs_fget_be32(guint32 *value, VFSFile *stream) +{ + guint32 tmp; + if (vfs_fread(&tmp, sizeof(guint32), 1, stream) != 1) + return FALSE; + *value = GUINT32_FROM_BE(tmp); + return TRUE; +} + +/** + * vfs_fget_be64: + * @value: Pointer to the variable to read the value into. + * @stream: A #VFSFile object representing the stream. + * + * Reads an unsigned 64-bit Big Endian value from the stream into native endian format. + * + * Return value: TRUE if read was succesful, FALSE if there was an error. + **/ +gboolean vfs_fget_be64(guint64 *value, VFSFile *stream) +{ + guint64 tmp; + if (vfs_fread(&tmp, sizeof(guint64), 1, stream) != 1) + return FALSE; + *value = GUINT64_FROM_BE(tmp); + return TRUE; +} + +