From 23752184c1e6a68261ab0953a463cbb834d4db22 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 5 Apr 2021 18:31:27 +0200 Subject: [PATCH] Make ReadM3U code use libretro-common file_stream --- libretro.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/libretro.cpp b/libretro.cpp index a53e362..549cb34 100644 --- a/libretro.cpp +++ b/libretro.cpp @@ -1427,18 +1427,19 @@ MDFNGI EmulatedPCE_Fast = 2, // Number of output sound channels }; -static bool ReadM3U(std::vector &file_list, std::string path, unsigned depth = 0) +static void ReadM3U(std::vector &file_list, std::string path, unsigned depth = 0) { std::string dir_path; char linebuf[2048]; - FILE *fp = fopen(path.c_str(), "rb"); + RFILE *fp = filestream_open(path.c_str(), RETRO_VFS_FILE_ACCESS_READ, + RETRO_VFS_FILE_ACCESS_HINT_NONE); if (!fp) - return false; + return; MDFN_GetFilePathComponents(path, &dir_path); - while(fgets(linebuf, sizeof(linebuf), fp)) + while(filestream_gets(fp, linebuf, sizeof(linebuf)) != NULL) { std::string efp; @@ -1455,15 +1456,13 @@ static bool ReadM3U(std::vector &file_list, std::string path, unsig if(efp == path) { log_cb(RETRO_LOG_ERROR, "M3U at \"%s\" references self.\n", efp.c_str()); - fclose(fp); - return false; + goto end; } if(depth == 99) { log_cb(RETRO_LOG_ERROR, "M3U load recursion too deep!\n"); - fclose(fp); - return false; + goto end; } ReadM3U(file_list, efp, depth++); @@ -1472,9 +1471,8 @@ static bool ReadM3U(std::vector &file_list, std::string path, unsig file_list.push_back(efp); } - fclose(fp); - - return true; +end: + filestream_close(fp); } static std::vector CDInterfaces; // FIXME: Cleanup on error out. @@ -1489,8 +1487,7 @@ static bool MDFNI_LoadCD(const char *devicename) { std::vector file_list; - if (ReadM3U(file_list, devicename)) - ret = true; + ReadM3U(file_list, devicename); for(unsigned i = 0; i < file_list.size(); i++) {