diff src/xs_support.c @ 955:3c2efa18c422

Change semantics of xs_fread_be{32,16}() functions to match xs_fread_str() and xs_fread_byte() and change the PSID/RSID file parsing for SLDB MD5 calculation to use them. Also, fix the parser so that PSID/RSID v3 files are supported correctly.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 20 Nov 2012 21:28:39 +0200
parents b2caef664524
children 0233c5fd7d5e
line wrap: on
line diff
--- a/src/xs_support.c	Tue Nov 20 21:27:26 2012 +0200
+++ b/src/xs_support.c	Tue Nov 20 21:28:39 2012 +0200
@@ -116,19 +116,23 @@
 }
 
 
-guint16 xs_fread_be16(XSFile *f)
+gboolean xs_fread_be16(XSFile *f, guint16 *val)
 {
-    return (((guint16) xs_fgetc(f)) << 8) | ((guint16) xs_fgetc(f));
+    guint16 result;
+    if (xs_fread(&result, sizeof(result), 1, f) != 1)
+        return FALSE;
+    *val = GUINT16_FROM_BE(result);
+    return TRUE;
 }
 
 
-guint32 xs_fread_be32(XSFile *f)
+gboolean xs_fread_be32(XSFile *f, guint32 *val)
 {
-    return
-        (((guint32) xs_fgetc(f)) << 24) |
-        (((guint32) xs_fgetc(f)) << 16) |
-        (((guint32) xs_fgetc(f)) << 8) |
-         ((guint32) xs_fgetc(f));
+    guint32 result;
+    if (xs_fread(&result, sizeof(result), 1, f) != 1)
+        return FALSE;
+    *val = GUINT32_FROM_BE(result);
+    return TRUE;
 }