# HG changeset patch # User Matti Hamalainen # Date 1206831482 -7200 # Node ID 9d5e6bfca6722cda3af6dcc5b5588c9a364f5501 # Parent a9c8efbfd4c20b34ad0d18bbcab69d529c6b44fc Added new VFS helper functions for reading big/little endian data (16-, 32- and 64-bit integer formats) diff -r a9c8efbfd4c2 -r 9d5e6bfca672 src/audacious/plugin.h --- 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 diff -r a9c8efbfd4c2 -r 9d5e6bfca672 src/audacious/vfs.h --- 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 */ diff -r a9c8efbfd4c2 -r 9d5e6bfca672 src/audacious/vfs_common.c --- 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; +} + +