Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/gc_disc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define GC_DISC_H
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <confluence/types.h>
#ifdef __cplusplus
extern "C" {
Expand All @@ -18,6 +19,7 @@ typedef enum {
GC_FORMAT_WBFS,
} GCDiscFormat;

FILE* gc_disc_fopen(const char* path);
GCDiscFormat gc_disc_detect_format(const char* path);
GCDisc* gc_disc_open(const char* path);
void gc_disc_close(GCDisc* disc);
Expand Down
29 changes: 27 additions & 2 deletions src/disc/gc_disc.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
#define _POSIX_C_SOURCE 200809L
#include "gc_disc_internal.h"
#include "siphon_log.h"
#include <stdlib.h>
#include <string.h>

#if defined(__ANDROID__) || defined(__linux__) || defined(__APPLE__)
#include <unistd.h>
#endif

FILE* gc_disc_fopen(const char* path) {
if (!path) return NULL;
#if defined(__ANDROID__) || defined(__linux__) || defined(__APPLE__)
if (strncmp(path, "fd:", 3) == 0) {
int fd = atoi(path + 3);
if (fd < 0) return NULL;
int dupfd = dup(fd);
if (dupfd < 0) return NULL;
FILE* f = fdopen(dupfd, "rb");
if (!f) {
close(dupfd);
return NULL;
}
rewind(f);
return f;
}
#endif
return fopen(path, "rb");
}

static const uint8_t MAGIC_CISO[4] = {'C','I','S','O'};
static const uint8_t MAGIC_WIA[4] = {'W','I','A',0x01};
static const uint8_t MAGIC_RVZ[4] = {'R','V','Z',0x01};
Expand All @@ -22,7 +47,7 @@ static const char* format_name(GCDiscFormat fmt) {
}

GCDiscFormat gc_disc_detect_format(const char* path) {
FILE* f = fopen(path, "rb");
FILE* f = gc_disc_fopen(path);
if (!f) return GC_FORMAT_UNKNOWN;

uint8_t hdr[4];
Expand All @@ -49,7 +74,7 @@ GCDisc* gc_disc_open(const char* path) {
GCDisc* disc = (GCDisc*)calloc(1, sizeof(GCDisc));
if (!disc) return NULL;

disc->file = fopen(path, "rb");
disc->file = gc_disc_fopen(path);
if (!disc->file) {
free(disc);
return NULL;
Expand Down
Loading