-#define core_file FILE
-#ifdef HAVE_LIBRETRO
-#include <compat/fopen_utf8.h>
-#define core_fopen(file) fopen_utf8(file, "rb")
-#else
-#define core_fopen(file) fopen(file, "rb")
-#endif
-#if defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WIN64__)
- #define core_fseek _fseeki64
- #define core_ftell _ftelli64
-#elif defined(_LARGEFILE_SOURCE) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
- #define core_fseek fseeko64
- #define core_ftell ftello64
-#else
- #define core_fseek fseeko
- #define core_ftell ftello
-#endif
-#define core_fread(fc, buff, len) fread(buff, 1, len, fc)
-#define core_fclose fclose
+typedef struct chd_core_file {
+ /*
+ * arbitrary pointer to data the implementation uses to implement the below functions
+ */
+ void *argp;
+
+ /*
+ * return the size of a given file as a 64-bit unsigned integer.
+ * the position of the file pointer after calling this function is
+ * undefined because many implementations will seek to the end of the
+ * file and call ftell.
+ *
+ * on error, (UINT64)-1 is returned.
+ */
+ UINT64(*fsize)(struct chd_core_file*);
+
+ /*
+ * should match the behavior of fread, except the FILE* argument at the end
+ * will be replaced with a struct chd_core_file*.
+ */
+ size_t(*fread)(void*,size_t,size_t,struct chd_core_file*);
+
+ // closes the given file.
+ int (*fclose)(struct chd_core_file*);
+
+ // fseek clone
+ int (*fseek)(struct chd_core_file*, INT64, int);
+} core_file;
+
+static inline int core_fclose(core_file *fp) {
+ return fp->fclose(fp);
+}
+
+static inline size_t core_fread(core_file *fp, void *ptr, size_t len) {
+ return fp->fread(ptr, 1, len, fp);
+}
+
+static inline int core_fseek(core_file* fp, INT64 offset, int whence) {
+ return fp->fseek(fp, offset, whence);
+}