some missing error handling
[pcsx_rearmed.git] / libpcsxcore / sio.c
index 329bc36..7aa669b 100644 (file)
 #include "sio.h"
 #include <sys/stat.h>
 
+#ifdef USE_LIBRETRO_VFS
+#include <streams/file_stream_transforms.h>
+#endif
+
 // Status Flags
 #define TX_RDY         0x0001
 #define RX_RDY         0x0002
@@ -407,6 +411,12 @@ void LoadMcd(int mcd, char *str) {
        }
 
        McdDisable[mcd - 1] = 0;
+#ifdef HAVE_LIBRETRO
+       // memcard1 is handled by libretro
+       if (mcd == 1)
+               return;
+#endif
+
        if (str == NULL || strcmp(str, "none") == 0) {
                McdDisable[mcd - 1] = 1;
                return;
@@ -428,7 +438,12 @@ void LoadMcd(int mcd, char *str) {
                                else if(buf.st_size == MCD_SIZE + 3904)
                                        fseek(f, 3904, SEEK_SET);
                        }
-                       fread(data, 1, MCD_SIZE, f);
+                       if (fread(data, 1, MCD_SIZE, f) != MCD_SIZE) {
+#ifndef NDEBUG
+                               SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+                               memset(data, 0x00, MCD_SIZE);
+                       }
                        fclose(f);
                }
                else
@@ -443,7 +458,12 @@ void LoadMcd(int mcd, char *str) {
                        else if(buf.st_size == MCD_SIZE + 3904)
                                fseek(f, 3904, SEEK_SET);
                }
-               fread(data, 1, MCD_SIZE, f);
+               if (fread(data, 1, MCD_SIZE, f) != MCD_SIZE) {
+#ifndef NDEBUG
+                       SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+                       memset(data, 0x00, MCD_SIZE);
+               }
                fclose(f);
        }
 }
@@ -658,6 +678,7 @@ void ConvertMcd(char *mcd, char *data) {
                        fclose(f);
                }
                f = fopen(mcd, "r+");
+               if (f == NULL) return;
                s = s + 3904;
                fputc('1', f); s--;
                fputc('2', f); s--;
@@ -692,6 +713,7 @@ void ConvertMcd(char *mcd, char *data) {
                        fclose(f);
                }
                f = fopen(mcd, "r+");
+               if (f == NULL) return;
                s = s + 64;
                fputc('V', f); s--;
                fputc('g', f); s--;