changeset 954:a5b118c853f5

Use xs_fread_str() and improve the probing of each backend to be more specific about what is accepted for the said backend.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 20 Nov 2012 21:27:26 +0200
parents b2caef664524
children 3c2efa18c422
files src/xs_sidplay1.cpp src/xs_sidplay2.cpp src/xs_sidplayfp.cpp
diffstat 3 files changed, 29 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/xs_sidplay1.cpp	Tue Nov 20 21:26:25 2012 +0200
+++ b/src/xs_sidplay1.cpp	Tue Nov 20 21:27:26 2012 +0200
@@ -52,14 +52,14 @@
  */
 gboolean xs_sidplay1_probe(XSFile *f)
 {
-    gchar tmpBuf[4];
-    
-    if (!f) return FALSE;
-    
-    if (xs_fread(tmpBuf, sizeof(gchar), 4, f) != 4)
+    gchar probe[16];
+
+    if (f == NULL || !xs_fread_str(f, (guint8 *) probe, sizeof(probe)))
         return FALSE;
-    
-    if (!strncmp(tmpBuf, "PSID", 4))
+
+    // Old libSIDPlay1 only supports PSIDv1, afaik
+    if (!strncmp(probe, "PSID", 4) &&
+        probe[4] == 0 && probe[5] == 1)
         return TRUE;
     else
         return FALSE;
--- a/src/xs_sidplay2.cpp	Tue Nov 20 21:26:25 2012 +0200
+++ b/src/xs_sidplay2.cpp	Tue Nov 20 21:27:26 2012 +0200
@@ -79,14 +79,18 @@
  */
 gboolean xs_sidplay2_probe(XSFile *f)
 {
-    gchar tmpBuf[5];
-    
-    if (!f) return FALSE;
-    
-    if (xs_fread(tmpBuf, sizeof(gchar), 4, f) != 4)
+    gchar probe[16];
+
+    if (f == NULL || !xs_fread_str(f, (guint8 *) probe, sizeof(probe)))
         return FALSE;
-    
-    if (!strncmp(tmpBuf, "PSID", 4) || !strncmp(tmpBuf, "RSID", 4))
+
+    // Old libSIDPlay2 does not support PSIDv3, afaik
+    if (!strncmp(probe, "PSID", 4) && probe[4] == 0 &&
+        probe[5] >= 1 && probe[5] <= 2)
+        return TRUE;
+    else
+    if (!strncmp(probe, "RSID", 4) &&
+        probe[4] == 0 && probe[5] == 2)
         return TRUE;
     else
         return FALSE;
--- a/src/xs_sidplayfp.cpp	Tue Nov 20 21:26:25 2012 +0200
+++ b/src/xs_sidplayfp.cpp	Tue Nov 20 21:27:26 2012 +0200
@@ -116,14 +116,18 @@
  */
 gboolean xs_sidplayfp_probe(XSFile *f)
 {
-    gchar tmpBuf[5];
-    
-    if (!f) return FALSE;
-    
-    if (xs_fread(tmpBuf, sizeof(gchar), 4, f) != 4)
+    gchar probe[16];
+
+    if (f == NULL || !xs_fread_str(f, (guint8 *) probe, sizeof(probe)))
         return FALSE;
-    
-    if (!strncmp(tmpBuf, "PSID", 4) || !strncmp(tmpBuf, "RSID", 4))
+
+    // Basically support all variants ..
+    if (!strncmp(probe, "PSID", 4) && probe[4] == 0 &&
+        probe[5] >= 1 && probe[5] <= 3)
+        return TRUE;
+    else
+    if (!strncmp(probe, "RSID", 4) &&
+        probe[4] == 0 && probe[5] >= 2 && probe[5] <= 3)
         return TRUE;
     else
         return FALSE;