shithub: m8c

Download patch

ref: a839ff9f9e8c02f42e49d3c6a7c32e20c38d0c4c
parent: f7cf5e28c1d666609cc01445ce5433d18e5fa207
author: smootalicious <smootalicious@gmail.com>
date: Mon Jun 13 19:16:51 EDT 2022

Changed strategy to use SDL functions only and removed stat.h strategy because it is not cross-platform.

--- a/input.c
+++ b/input.c
@@ -3,7 +3,6 @@
 
 #include <SDL.h>
 #include <stdio.h>
-#include <sys/stat.h>
 
 #include "config.h"
 #include "input.h"
@@ -54,12 +53,14 @@
   char db_filename[1024] = {0};
   snprintf(db_filename, sizeof(db_filename), "%sgamecontrollerdb.txt",
            SDL_GetPrefPath("", "m8c"));
-  SDL_Log("Looking for game controller database at %s", db_filename);
-  struct stat buffer;   
-  if ( (stat (db_filename, &buffer) != 0))   snprintf(db_filename, sizeof(db_filename), "%sgamecontrollerdb.txt",
-           SDL_GetBasePath());
   SDL_Log("Trying to open game controller database from %s", db_filename);
-  SDL_RWops *db_rw = SDL_RWFromFile(db_filename, "rb");
+  SDL_RWops* db_rw = SDL_RWFromFile(db_filename, "rb");
+  if (db_rw == NULL) {
+    snprintf(db_filename, sizeof(db_filename), "%sgamecontrollerdb.txt",
+    SDL_GetBasePath());
+    SDL_Log("Trying to open game controller database from %s", db_filename);
+    db_rw = SDL_RWFromFile(db_filename, "rb");
+  }
 
   if (db_rw != NULL) {
     int mappings = SDL_GameControllerAddMappingsFromRW(db_rw, 1);
--