diff --git a/src/Platform.h b/src/Platform.h index fe551df5a..746c75264 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -53,13 +53,12 @@ cc_bool Platform_DescribeErrorExt(cc_result res, cc_string* dst, void* lib); #endif #ifdef CC_BUILD_WIN -typedef cc_winstring cc_filepath; -typedef cc_winstring* cc_filepath_ptr; +typedef cc_winstring cc_filepath; #else -typedef char cc_filepath[NATIVE_STR_LEN]; -typedef char* cc_filepath_ptr; +typedef struct cc_filepath_ { char buffer[NATIVE_STR_LEN]; } cc_filepath; +#define FILEPATH_RAW(raw) ((cc_filepath*)raw) #endif -void Platform_EncodePath(cc_filepath_ptr dst, const cc_string* src); +void Platform_EncodePath(cc_filepath* dst, const cc_string* src); /* Initialises the platform specific state. */ void Platform_Init(void); @@ -192,7 +191,7 @@ CC_API cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end); int Stopwatch_ElapsedMS(cc_uint64 beg, cc_uint64 end); /* Attempts to create a new directory. */ -cc_result Directory_Create(cc_filepath_ptr path); +cc_result Directory_Create(const cc_filepath* path); /* Callback function invoked for each file found. */ typedef void (*Directory_EnumCallback)(const cc_string* filename, void* obj, int isDirectory); /* Invokes a callback function on all filenames in the given directory (and its sub-directories) */ @@ -203,11 +202,11 @@ void Directory_GetCachePath(cc_string* path); /* Attempts to create a new (or overwrite) file for writing. */ /* NOTE: If the file already exists, its contents are discarded. */ -cc_result File_Create(cc_file* file, cc_filepath_ptr path); +cc_result File_Create(cc_file* file, const cc_filepath* path); /* Attempts to open an existing file for reading. */ -cc_result File_Open(cc_file* file, cc_filepath_ptr path); +cc_result File_Open(cc_file* file, const cc_filepath* path); /* Attempts to open an existing or create a new file for reading and writing. */ -cc_result File_OpenOrCreate(cc_file* file, cc_filepath_ptr path); +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path); /* Attempts to read data from the file. */ cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead); /* Attempts to write data to the file. */ diff --git a/src/Platform_3DS.c b/src/Platform_3DS.c index 3925f87dc..56a26a74b 100644 --- a/src/Platform_3DS.c +++ b/src/Platform_3DS.c @@ -91,14 +91,15 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) { *#########################################################################################################################*/ static const cc_string root_path = String_FromConst("sdmc:/3ds/ClassiCube/"); -void Platform_EncodePath(char* str, const cc_string* path) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; Mem_Copy(str, root_path.buffer, root_path.length); str += root_path.length; String_EncodeUtf8(str, path); } -cc_result Directory_Create(char* path) { - return mkdir(path, 0666) == -1 ? errno : 0; // FS has no permissions anyways +cc_result Directory_Create(const cc_filepath* path) { + return mkdir(path->buffer, 0666) == -1 ? errno : 0; // FS has no permissions anyways } int File_Exists(const cc_string* path) { @@ -149,14 +150,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { return *file == -1 ? errno : 0; } -cc_result File_Open(cc_file* file, char* path) { - return File_Do(file, path, O_RDONLY); +cc_result File_Open(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, O_RDONLY); } -cc_result File_Create(cc_file* file, char* path) { - return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC); +cc_result File_Create(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, char* path) { - return File_Do(file, path, O_RDWR | O_CREAT); +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, O_RDWR | O_CREAT); } cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) { diff --git a/src/Platform_Dreamcast.c b/src/Platform_Dreamcast.c index 217139ad8..91e94bbaa 100644 --- a/src/Platform_Dreamcast.c +++ b/src/Platform_Dreamcast.c @@ -187,14 +187,15 @@ static cc_result VMUFile_Close(cc_file file) { *#########################################################################################################################*/ static cc_string root_path = String_FromConst("/cd/"); -void Platform_EncodePath(char* str, const cc_string* path) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; Mem_Copy(str, root_path.buffer, root_path.length); str += root_path.length; String_EncodeUtf8(str, path); } -cc_result Directory_Create(char* path) { - int res = fs_mkdir(path); +cc_result Directory_Create(const cc_filepath* path { + int res = fs_mkdir(path->buffer); int err = res == -1 ? errno : 0; // Filesystem returns EINVAL when operation unsupported (e.g. CD system) @@ -249,7 +250,7 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall return err; } -static cc_result File_Do(cc_file* file, char* path, int mode) { +static cc_result File_Do(cc_file* file, const char* path, int mode) { // CD filesystem loader doesn't usually set errno // when it can't find the requested file errno = 0; @@ -268,14 +269,14 @@ static cc_result File_Do(cc_file* file, char* path, int mode) { return err; } -cc_result File_Open(cc_file* file, char* path) { - return File_Do(file, path, O_RDONLY); +cc_result File_Open(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, O_RDONLY); } -cc_result File_Create(cc_file* file, char* path) { - return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC); +cc_result File_Create(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, char* path) { - return File_Do(file, path, O_RDWR | O_CREAT); +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, O_RDWR | O_CREAT); } cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) { diff --git a/src/Platform_GCWii.c b/src/Platform_GCWii.c index 81a8e6cfa..e031164e8 100644 --- a/src/Platform_GCWii.c +++ b/src/Platform_GCWii.c @@ -119,17 +119,18 @@ static bool fat_available; // FindDevice() returns -1 when no matching device, however the code still unconditionally does "if (devoptab_list[dev]->mkdir_r) {" // - so will either attempt to access or execute invalid memory -void Platform_EncodePath(char* str, const cc_string* path) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; Mem_Copy(str, root_path.buffer, root_path.length); str += root_path.length; *str++ = '/'; String_EncodeUtf8(str, path); } -cc_result Directory_Create(char* path) { +cc_result Directory_Create(const cc_filepath* path) { if (!fat_available) return ENOSYS; - return mkdir(path, 0) == -1 ? errno : 0; + return mkdir(path->buffer, 0) == -1 ? errno : 0; } int File_Exists(const cc_string* path) { @@ -181,24 +182,24 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall return res; } -static cc_result File_Do(cc_file* file, char* path, int mode) { +static cc_result File_Do(cc_file* file, const char* path, int mode) { *file = open(path, mode, 0); return *file == -1 ? errno : 0; } -cc_result File_Open(cc_file* file, char* path) { +cc_result File_Open(cc_file* file, const cc_filepath* path) { if (!fat_available) return ReturnCode_FileNotFound; - return File_Do(file, path, O_RDONLY); + return File_Do(file, path->buffer, O_RDONLY); } -cc_result File_Create(cc_file* file, char* path) { +cc_result File_Create(cc_file* file, const cc_filepath* path) { if (!fat_available) return ENOTSUP; - return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC); + return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, char* path) { +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { if (!fat_available) return ENOTSUP; - return File_Do(file, path, O_RDWR | O_CREAT); + return File_Do(file, path->buffer, O_RDWR | O_CREAT); } cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) { diff --git a/src/Platform_MacClassic.c b/src/Platform_MacClassic.c index 6273614e4..044d7bdc5 100644 --- a/src/Platform_MacClassic.c +++ b/src/Platform_MacClassic.c @@ -165,8 +165,8 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) { *#########################################################################################################################*/ static int retrievedWD, wd_refNum, wd_dirID; -void Platform_EncodePath(char* dst, const cc_string* src) { - char* str = dst; +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; str++; // placeholder for length later *str++ = ':'; @@ -231,8 +231,8 @@ static int DoCreateFolder(char* name) { void Directory_GetCachePath(cc_string* path) { } -cc_result Directory_Create(char* path) { - return DoCreateFolder(path); +cc_result Directory_Create(const cc_filepath* path) { + return DoCreateFolder(path->buffer); } int File_Exists(const cc_string* path) { @@ -246,22 +246,22 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall return ERR_NOT_SUPPORTED; } -cc_result File_Open(cc_file* file, char* path) { - return DoOpenDF(path, fsRdPerm, file); +cc_result File_Open(cc_file* file, const cc_filepath* path) { + return DoOpenDF(path->buffer, fsRdPerm, file); } -cc_result File_Create(cc_file* file, char* path) { - int res = DoCreateFile(path); +cc_result File_Create(cc_file* file, const cc_filepath* path) { + int res = DoCreateFile(path->buffer); if (res && res != dupFNErr) return res; - return DoOpenDF(path, fsWrPerm, file); + return DoOpenDF(path->buffer, fsWrPerm, file); } -cc_result File_OpenOrCreate(cc_file* file, char* path) { - int res = DoCreateFile(path); +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { + int res = DoCreateFile(path->buffer); if (res && res != dupFNErr) return res; - return DoOpenDF(path, fsRdWrPerm, file); + return DoOpenDF(path->buffer, fsRdWrPerm, file); } cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) { diff --git a/src/Platform_N64.c b/src/Platform_N64.c index da239b617..ba769180d 100644 --- a/src/Platform_N64.c +++ b/src/Platform_N64.c @@ -70,7 +70,8 @@ void DateTime_CurrentLocal(struct DateTime* t) { *#########################################################################################################################*/ static const cc_string root_path = String_FromConst("/"); -void Platform_EncodePath(char* str, const cc_string* path) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; // TODO temp hack cc_string path_ = *path; int idx = String_IndexOf(path, '/'); @@ -81,7 +82,7 @@ void Platform_EncodePath(char* str, const cc_string* path) { String_EncodeUtf8(str, &path_); } -cc_result Directory_Create(char* path) { +cc_result Directory_Create(const cc_filepath* path) { return ERR_NOT_SUPPORTED; } @@ -93,7 +94,7 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall return ERR_NOT_SUPPORTED; // TODO add support } -static cc_result File_Do(cc_file* file, char* path) { +static cc_result File_Do(cc_file* file, const char* path) { //*file = -1; //return ReturnCode_FileNotFound; // TODO: Why does trying this code break everything @@ -106,18 +107,18 @@ static cc_result File_Do(cc_file* file, char* path) { return 0; } -cc_result File_Open(cc_file* file, char* path) { - return File_Do(file, path); +cc_result File_Open(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer); } -cc_result File_Create(cc_file* file, char* path) { +cc_result File_Create(cc_file* file, const cc_filepath* path) { *file = -1; return ERR_NOT_SUPPORTED; - //return File_Do(file, path); + //return File_Do(file, path->buffer); } -cc_result File_OpenOrCreate(cc_file* file, char* path) { +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { *file = -1; return ERR_NOT_SUPPORTED; - //return File_Do(file, path); + //return File_Do(file, path->buffer); } cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) { diff --git a/src/Platform_NDS.c b/src/Platform_NDS.c index 7b9cb0028..d7200779b 100644 --- a/src/Platform_NDS.c +++ b/src/Platform_NDS.c @@ -109,17 +109,18 @@ void DateTime_CurrentLocal(struct DateTime* t) { static cc_string root_path = String_FromConst("fat:/"); // may be overriden in InitFilesystem static bool fat_available; -void Platform_EncodePath(char* str, const cc_string* path) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; Mem_Copy(str, root_path.buffer, root_path.length); str += root_path.length; String_EncodeUtf8(str, path); } -cc_result Directory_Create(char* path) { +cc_result Directory_Create(const cc_filepath* path) { if (!fat_available) return 0; - Platform_Log1("mkdir %c", path); - return mkdir(path, 0) == -1 ? errno : 0; + Platform_Log1("mkdir %c", path->buffer); + return mkdir(path->buffer, 0) == -1 ? errno : 0; } int File_Exists(const cc_string* path) { @@ -170,26 +171,26 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall return res; } -static cc_result File_Do(cc_file* file, char* path, int mode, const char* type) { +static cc_result File_Do(cc_file* file, const char* path, int mode, const char* type) { Platform_Log2("%c %c", type, path); *file = open(path, mode, 0); return *file == -1 ? errno : 0; } -cc_result File_Open(cc_file* file, char* path) { +cc_result File_Open(cc_file* file, const cc_filepath* path) { if (!fat_available) return ReturnCode_FileNotFound; - return File_Do(file, path, O_RDONLY, "Open"); + return File_Do(file, path->buffer, O_RDONLY, "Open"); } -cc_result File_Create(cc_file* file, char* path) { +cc_result File_Create(cc_file* file, const cc_filepath* path) { if (!fat_available) return ENOTSUP; - return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC, "Create"); + return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC, "Create"); } -cc_result File_OpenOrCreate(cc_file* file, char* path) { +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { if (!fat_available) return ENOTSUP; - return File_Do(file, path, O_RDWR | O_CREAT, "Update"); + return File_Do(file, path->buffer, O_RDWR | O_CREAT, "Update"); } cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) { diff --git a/src/Platform_PS1.c b/src/Platform_PS1.c index 0ae0612f3..5c8ba7fa9 100644 --- a/src/Platform_PS1.c +++ b/src/Platform_PS1.c @@ -87,13 +87,14 @@ static void Stopwatch_Init(void) { *#########################################################################################################################*/ static const cc_string root_path = String_FromConst("cdrom:/"); -void Platform_EncodePath(char* str, const cc_string* path) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; Mem_Copy(str, root_path.buffer, root_path.length); str += root_path.length; String_EncodeUtf8(str, path); } -cc_result Directory_Create(char* path) { +cc_result Directory_Create(const cc_filepath* path) { return ERR_NOT_SUPPORTED; } @@ -105,15 +106,15 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall return ERR_NOT_SUPPORTED; } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, const cc_filepath* path) { return ERR_NOT_SUPPORTED; } -cc_result File_Create(cc_file* file, char* path) { +cc_result File_Create(cc_file* file, const cc_filepath* path) { return ERR_NOT_SUPPORTED; } -cc_result File_OpenOrCreate(cc_file* file, char* path) { +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { return ERR_NOT_SUPPORTED; } diff --git a/src/Platform_PS2.c b/src/Platform_PS2.c index ea0d0ad67..84d6f1b84 100644 --- a/src/Platform_PS2.c +++ b/src/Platform_PS2.c @@ -107,14 +107,15 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) { *#########################################################################################################################*/ static const cc_string root_path = String_FromConst("mass:/ClassiCube/"); -void Platform_EncodePath(char* str, const cc_string* path) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; Mem_Copy(str, root_path.buffer, root_path.length); str += root_path.length; String_EncodeUtf8(str, path); } -cc_result Directory_Create(char* path) { - return fioMkdir(path); +cc_result Directory_Create(const cc_filepath* pathh) { + return fioMkdir(path->buffer); } int File_Exists(const cc_string* path) { @@ -178,14 +179,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { return res < 0 ? res : 0; } -cc_result File_Open(cc_file* file, char* path) { - return File_Do(file, path, FIO_O_RDONLY); +cc_result File_Open(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, FIO_O_RDONLY); } -cc_result File_Create(cc_file* file, char* path) { - return File_Do(file, path, FIO_O_RDWR | FIO_O_CREAT | FIO_O_TRUNC); +cc_result File_Create(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, FIO_O_RDWR | FIO_O_CREAT | FIO_O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, char* path) { - return File_Do(file, path, FIO_O_RDWR | FIO_O_CREAT); +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, FIO_O_RDWR | FIO_O_CREAT); } cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) { diff --git a/src/Platform_PS3.c b/src/Platform_PS3.c index d65ac91ba..d2745dc84 100644 --- a/src/Platform_PS3.c +++ b/src/Platform_PS3.c @@ -95,16 +95,17 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) { *#########################################################################################################################*/ static const cc_string root_path = String_FromConst("/dev_hdd0/ClassiCube/"); -void Platform_EncodePath(char* str, const cc_string* path) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; Mem_Copy(str, root_path.buffer, root_path.length); str += root_path.length; String_EncodeUtf8(str, path); } -cc_result Directory_Create(char* path) { +cc_result Directory_Create(const cc_filepath* path) { /* read/write/search permissions for owner and group, and with read/search permissions for others. */ /* TODO: Is the default mode in all cases */ - return sysLv2FsMkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + return sysLv2FsMkdir(path->buffer, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); } int File_Exists(const cc_string* path) { @@ -164,14 +165,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { } } -cc_result File_Open(cc_file* file, char* path) { - return File_Do(file, path, SYS_O_RDONLY); +cc_result File_Open(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, SYS_O_RDONLY); } -cc_result File_Create(cc_file* file, char* path) { - return File_Do(file, path, SYS_O_RDWR | SYS_O_CREAT | SYS_O_TRUNC); +cc_result File_Create(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, SYS_O_RDWR | SYS_O_CREAT | SYS_O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, char* path) { - return File_Do(file, path, SYS_O_RDWR | SYS_O_CREAT); +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, SYS_O_RDWR | SYS_O_CREAT); } cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) { @@ -444,7 +445,9 @@ cc_result Socket_CheckWritable(cc_socket s, cc_bool* writable) { *#########################################################################################################################*/ void Platform_Init(void) { netInitialize(); - Directory_Create(root_path.buffer); + + cc_filepath* root = FILEPATH_RAW(root_path.buffer); + Directory_Create(root); } void Platform_Free(void) { } diff --git a/src/Platform_PSP.c b/src/Platform_PSP.c index 3fa627b7a..379518bac 100644 --- a/src/Platform_PSP.c +++ b/src/Platform_PSP.c @@ -86,7 +86,8 @@ cc_uint64 Stopwatch_Measure(void) { *#########################################################################################################################*/ static const cc_string root_path = String_FromConst("ms0:/PSP/GAME/ClassiCube/"); -void Platform_EncodePath(char* str, const cc_string* path) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; Mem_Copy(str, root_path.buffer, root_path.length); str += root_path.length; String_EncodeUtf8(str, path); @@ -94,8 +95,8 @@ void Platform_EncodePath(char* str, const cc_string* path) { #define GetSCEResult(result) (result >= 0 ? 0 : result & 0xFFFF) -cc_result Directory_Create(char* path) { - int result = sceIoMkdir(str, 0777); +cc_result Directory_Create(const cc_filepath* path) { + int result = sceIoMkdir(path->buffer, 0777); return GetSCEResult(result); } @@ -144,14 +145,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { return GetSCEResult(result); } -cc_result File_Open(cc_file* file, char* path) { - return File_Do(file, path, PSP_O_RDONLY); +cc_result File_Open(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, PSP_O_RDONLY); } -cc_result File_Create(cc_file* file, char* path) { - return File_Do(file, path, PSP_O_RDWR | PSP_O_CREAT | PSP_O_TRUNC); +cc_result File_Create(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, PSP_O_RDWR | PSP_O_CREAT | PSP_O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, char* path) { - return File_Do(file, path, PSP_O_RDWR | PSP_O_CREAT); +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, PSP_O_RDWR | PSP_O_CREAT); } cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) { @@ -428,8 +429,9 @@ void Platform_Init(void) { // *tx = vel->x == 0.0f ? MATH_LARGENUM : Math_AbsF(dx / vel->x); // TODO: work out why this error is actually happening (inexact or underflow?) and properly fix it pspSdkDisableFPUExceptions(); - - Directory_Create(root_path.buffer); + + cc_filepath* root = FILEPATH_RAW(root_path.buffer); + Directory_Create(root); } void Platform_Free(void) { } diff --git a/src/Platform_PSVita.c b/src/Platform_PSVita.c index 0b53f69e3..ed9c5cd1a 100644 --- a/src/Platform_PSVita.c +++ b/src/Platform_PSVita.c @@ -69,7 +69,8 @@ cc_uint64 Stopwatch_Measure(void) { *#########################################################################################################################*/ static const cc_string root_path = String_FromConst("ux0:data/ClassiCube/"); -void Platform_EncodePath(char* str, const cc_string* path) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; Mem_Copy(str, root_path.buffer, root_path.length); str += root_path.length; String_EncodeUtf8(str, path); @@ -77,8 +78,8 @@ void Platform_EncodePath(char* str, const cc_string* path) { #define GetSCEResult(result) (result >= 0 ? 0 : result & 0xFFFF) -cc_result Directory_Create(char* path) { - int result = sceIoMkdir(path, 0777); +cc_result Directory_Create(const cc_filepath* path) { + int result = sceIoMkdir(path->buffer, 0777); return GetSCEResult(result); } @@ -127,14 +128,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { return GetSCEResult(result); } -cc_result File_Open(cc_file* file, char* path) { - return File_Do(file, path, SCE_O_RDONLY); +cc_result File_Open(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, SCE_O_RDONLY); } -cc_result File_Create(cc_file* file, char* path) { - return File_Do(file, path, SCE_O_RDWR | SCE_O_CREAT | SCE_O_TRUNC); +cc_result File_Create(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, SCE_O_RDWR | SCE_O_CREAT | SCE_O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, char* path) { - return File_Do(file, path, SCE_O_RDWR | SCE_O_CREAT); +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, SCE_O_RDWR | SCE_O_CREAT); } cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) { @@ -385,7 +386,9 @@ void Platform_Init(void) { /*pspDebugSioInit();*/ InitNetworking(); epoll_id = sceNetEpollCreate("CC poll", 0); - Directory_Create(root_path.buffer); + + cc_filepath* root = FILEPATH_RAW(root_path.buffer); + Directory_Create(root); } void Platform_Free(void) { } diff --git a/src/Platform_Posix.c b/src/Platform_Posix.c index e162cc5bf..51ebae122 100644 --- a/src/Platform_Posix.c +++ b/src/Platform_Posix.c @@ -189,7 +189,8 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) { /*########################################################################################################################* *-----------------------------------------------------Directory/File------------------------------------------------------* *#########################################################################################################################*/ -void Platform_EncodePath(char* str, const cc_string* path) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; String_EncodeUtf8(str, path); } @@ -201,10 +202,10 @@ void Platform_EncodePath(char* str, const cc_string* path) { void Directory_GetCachePath(cc_string* path) { } #endif -cc_result Directory_Create(char* path) { +cc_result Directory_Create(const cc_filepath* path) { /* read/write/search permissions for owner and group, and with read/search permissions for others. */ /* TODO: Is the default mode in all cases */ - return mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 ? errno : 0; + return mkdir(path->buffer, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 ? errno : 0; } int File_Exists(const cc_string* path) { @@ -270,25 +271,25 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { return *file == -1 ? errno : 0; } -cc_result File_Open(cc_file* file, char* path) { +cc_result File_Open(cc_file* file, const cc_filepath* path) { #if !defined CC_BUILD_OS2 - return File_Do(file, path, O_RDONLY); + return File_Do(file, path->buffer, O_RDONLY); #else - return File_Do(file, path, O_RDONLY | O_BINARY); + return File_Do(file, path->buffer, O_RDONLY | O_BINARY); #endif } -cc_result File_Create(cc_file* file, char* path) { +cc_result File_Create(cc_file* file, const cc_filepath* path) { #if !defined CC_BUILD_OS2 - return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC); + return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC); #else - return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY); + return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC | O_BINARY); #endif } -cc_result File_OpenOrCreate(cc_file* file, char* path) { +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { #if !defined CC_BUILD_OS2 - return File_Do(file, path, O_RDWR | O_CREAT); + return File_Do(file, path->buffer, O_RDWR | O_CREAT); #else - return File_Do(file, path, O_RDWR | O_CREAT | O_BINARY); + return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_BINARY); #endif } diff --git a/src/Platform_Saturn.c b/src/Platform_Saturn.c index e884af59a..8ef07d2a5 100644 --- a/src/Platform_Saturn.c +++ b/src/Platform_Saturn.c @@ -85,11 +85,12 @@ static void Stopwatch_Init(void) { /*########################################################################################################################* *-----------------------------------------------------Directory/File------------------------------------------------------* *#########################################################################################################################*/ -void Platform_EncodePath(char* str, const cc_string* path) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; String_EncodeUtf8(str, path); } -cc_result Directory_Create(char* path) { +cc_result Directory_Create(const cc_filepath* path) { return ERR_NOT_SUPPORTED; } @@ -101,15 +102,15 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall return ERR_NOT_SUPPORTED; } -cc_result File_Open(cc_file* file, char* path) { +cc_result File_Open(cc_file* file, const cc_filepath* path) { return ERR_NOT_SUPPORTED; } -cc_result File_Create(cc_file* file, char* path) { +cc_result File_Create(cc_file* file, const cc_filepath* path) { return ERR_NOT_SUPPORTED; } -cc_result File_OpenOrCreate(cc_file* file, char* path) { +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { return ERR_NOT_SUPPORTED; } diff --git a/src/Platform_Switch.c b/src/Platform_Switch.c index b93677b21..d59d22a7e 100644 --- a/src/Platform_Switch.c +++ b/src/Platform_Switch.c @@ -109,14 +109,15 @@ void DateTime_CurrentLocal(struct DateTime* t) { *#########################################################################################################################*/ static const cc_string root_path = String_FromConst("sdmc:/switch/ClassiCube/"); -void Platform_EncodePath(char* str, const cc_string* path) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; Mem_Copy(str, root_path.buffer, root_path.length); str += root_path.length; String_EncodeUtf8(str, path); } -cc_result Directory_Create(char* path) { - return mkdir(path, 0) == -1 ? errno : 0; +cc_result Directory_Create(const cc_filepath* path) { + return mkdir(path->buffer, 0) == -1 ? errno : 0; } int File_Exists(const cc_string* path) { @@ -169,14 +170,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { return *file == -1 ? errno : 0; } -cc_result File_Open(cc_file* file, char* path) { - return File_Do(file, path, O_RDONLY); +cc_result File_Open(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, O_RDONLY); } -cc_result File_Create(cc_file* file, char* path) { - return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC); +cc_result File_Create(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, char* path) { - return File_Do(file, path, O_RDWR | O_CREAT); +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, O_RDWR | O_CREAT); } cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) { diff --git a/src/Platform_Web.c b/src/Platform_Web.c index 970b348b6..93539f0f4 100644 --- a/src/Platform_Web.c +++ b/src/Platform_Web.c @@ -100,14 +100,15 @@ void DateTime_CurrentLocal(struct DateTime* t) { /*########################################################################################################################* *-----------------------------------------------------Directory/File------------------------------------------------------* *#########################################################################################################################*/ -void Platform_EncodePath(char* str, const cc_string* path) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; String_EncodeUtf8(str, path); } void Directory_GetCachePath(cc_string* path) { } extern void interop_InitFilesystem(void); -cc_result Directory_Create(char* path) { +cc_result Directory_Create(const cc_filepath* path) { /* Web filesystem doesn't need directories */ return 0; } @@ -152,14 +153,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { } } -cc_result File_Open(cc_file* file, char* path) { - return File_Do(file, path, O_RDONLY); +cc_result File_Open(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, O_RDONLY); } -cc_result File_Create(cc_file* file, char* path) { - return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC); +cc_result File_Create(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, char* path) { - return File_Do(file, path, O_RDWR | O_CREAT); +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, O_RDWR | O_CREAT); } extern int interop_FileRead(int fd, void* data, int count); diff --git a/src/Platform_WiiU.c b/src/Platform_WiiU.c index 36ec1d1a4..463257a06 100644 --- a/src/Platform_WiiU.c +++ b/src/Platform_WiiU.c @@ -103,16 +103,17 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) { static const cc_string root_path = String_FromConst("ClassiCube/"); -void Platform_EncodePath(char* str, const cc_string* path) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; Mem_Copy(str, root_path.buffer, root_path.length); str += root_path.length; String_EncodeUtf8(str, path); } -cc_result Directory_Create(char* path) { +cc_result Directory_Create(const cc_filepath* path) { /* read/write/search permissions for owner and group, and with read/search permissions for others. */ /* TODO: Is the default mode in all cases */ - return mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 ? errno : 0; + return mkdir(path->buffer, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 ? errno : 0; } int File_Exists(const cc_string* path) { @@ -168,14 +169,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { return *file == -1 ? errno : 0; } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, const cc_filepath* path) { return File_Do(file, path, O_RDONLY); } -cc_result File_Create(cc_file* file, const char* path) { - return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC); +cc_result File_Create(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, const char* path) { - return File_Do(file, path, O_RDWR | O_CREAT); +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, O_RDWR | O_CREAT); } cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) { diff --git a/src/Platform_Windows.c b/src/Platform_Windows.c index 282edc7d5..0d123caee 100644 --- a/src/Platform_Windows.c +++ b/src/Platform_Windows.c @@ -180,11 +180,11 @@ cc_uint64 Stopwatch_Measure(void) { *#########################################################################################################################*/ void Directory_GetCachePath(cc_string* path) { } -void Platform_EncodePath(cc_filepath_ptr dst, const cc_string* src) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* src) { Platform_EncodeString(dst, src); } -cc_result Directory_Create(cc_filepath_ptr path) { +cc_result Directory_Create(const cc_filepath* path) { cc_result res; if (CreateDirectoryW(path->uni, NULL)) return 0; /* Windows 9x does not support W API functions */ @@ -280,13 +280,13 @@ static cc_result DoFile(cc_file* file, const cc_filepath* path, DWORD access, DW return *file != INVALID_HANDLE_VALUE ? 0 : GetLastError(); } -cc_result File_Open(cc_file* file, cc_filepath_ptr path) { +cc_result File_Open(cc_file* file, const cc_filepath* path) { return DoFile(file, path, GENERIC_READ, OPEN_EXISTING); } -cc_result File_Create(cc_file* file, cc_filepath_ptr path) { +cc_result File_Create(cc_file* file, const cc_filepath* path) { return DoFile(file, path, GENERIC_WRITE | GENERIC_READ, CREATE_ALWAYS); } -cc_result File_OpenOrCreate(cc_file* file, cc_filepath_ptr path) { +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { return DoFile(file, path, GENERIC_WRITE | GENERIC_READ, OPEN_ALWAYS); } diff --git a/src/Platform_Xbox.c b/src/Platform_Xbox.c index e981f3931..5acc10974 100644 --- a/src/Platform_Xbox.c +++ b/src/Platform_Xbox.c @@ -86,7 +86,8 @@ static void Stopwatch_Init(void) { static cc_string root_path = String_FromConst("E:\\ClassiCube\\"); static BOOL hdd_mounted; -void Platform_EncodePath(char* str, const cc_string* src) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; Mem_Copy(str, root_path.buffer, root_path.length); str += root_path.length; @@ -100,10 +101,10 @@ void Platform_EncodePath(char* str, const cc_string* src) { *str = '\0'; } -cc_result Directory_Create(char* path) { +cc_result Directory_Create(const cc_filepath* path) { if (!hdd_mounted) return ERR_NOT_SUPPORTED; - return CreateDirectoryA(path, NULL) ? 0 : GetLastError(); + return CreateDirectoryA(path->buffer, NULL) ? 0 : GetLastError(); } int File_Exists(const cc_string* path) { @@ -168,19 +169,19 @@ static cc_result DoFile(cc_file* file, const char* path, DWORD access, DWORD cre return *file != INVALID_HANDLE_VALUE ? 0 : GetLastError(); } -cc_result File_Open(cc_file* file, char* path) { +cc_result File_Open(cc_file* file, const cc_filepath* path) { if (!hdd_mounted) return ReturnCode_FileNotFound; - return DoFile(file, path, GENERIC_READ, OPEN_EXISTING); + return DoFile(file, path->buffer, GENERIC_READ, OPEN_EXISTING); } -cc_result File_Create(cc_file* file, char* path) { +cc_result File_Create(cc_file* file, const cc_filepath* path) { if (!hdd_mounted) return ERR_NOT_SUPPORTED; - return DoFile(file, path, GENERIC_WRITE | GENERIC_READ, CREATE_ALWAYS); + return DoFile(file, path->buffer, GENERIC_WRITE | GENERIC_READ, CREATE_ALWAYS); } -cc_result File_OpenOrCreate(cc_file* file, char* path) { +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { if (!hdd_mounted) return ERR_NOT_SUPPORTED; - return DoFile(file, path, GENERIC_WRITE | GENERIC_READ, OPEN_ALWAYS); + return DoFile(file, path->buffer, GENERIC_WRITE | GENERIC_READ, OPEN_ALWAYS); } cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) { @@ -411,7 +412,9 @@ static void InitHDD(void) { Platform_LogConst("Failed to mount E:/ from Data partition"); return; } - Directory_Create(root_path.buffer); + + cc_filepath* root = FILEPATH_RAW(root_path.buffer); + Directory_Create(root); } void Platform_Init(void) { diff --git a/src/Platform_Xbox360.c b/src/Platform_Xbox360.c index 0a5565270..3f414c6b9 100644 --- a/src/Platform_Xbox360.c +++ b/src/Platform_Xbox360.c @@ -78,14 +78,15 @@ cc_uint64 Stopwatch_Measure(void) { static char root_buffer[NATIVE_STR_LEN]; static cc_string root_path = String_FromArray(root_buffer); -void Platform_EncodePath(char* str, const cc_string* path) { +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; Mem_Copy(str, root_path.buffer, root_path.length); str += root_path.length; String_EncodeUtf8(str, path); } -cc_result Directory_Create(char* path) { - return mkdir(path, 0) == -1 ? errno : 0; +cc_result Directory_Create(const cc_filepath* path) { + return mkdir(path->buffer, 0) == -1 ? errno : 0; } int File_Exists(const cc_string* path) { @@ -138,14 +139,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { return *file == -1 ? errno : 0; } -cc_result File_Open(cc_file* file, char* path) { - return File_Do(file, path, O_RDONLY); +cc_result File_Open(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, O_RDONLY); } -cc_result File_Create(cc_file* file, char* path) { - return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC); +cc_result File_Create(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, char* path) { - return File_Do(file, path, O_RDWR | O_CREAT); +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { + return File_Do(file, path->buffer, O_RDWR | O_CREAT); } cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) { diff --git a/src/Window_Android.c b/src/Window_Android.c index 70f52e6c6..840661e20 100644 --- a/src/Window_Android.c +++ b/src/Window_Android.c @@ -450,7 +450,7 @@ cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* save_args) { if (!save_args->defaultName.length) return SFD_ERR_NEED_DEFAULT_NAME; // save the item to a temp file, which is then (usually) later deleted by intent callback - Directory_Create("Exported"); + Directory_Create(FILEPATH_RAW("Exported")); cc_string path; char pathBuffer[FILENAME_SIZE]; String_InitArray(path, pathBuffer); diff --git a/src/interop_ios.m b/src/interop_ios.m index 48d726b40..2a6f941f3 100644 --- a/src/interop_ios.m +++ b/src/interop_ios.m @@ -668,7 +668,7 @@ cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) { // UIDocumentPickerViewController - iOS 8.0 // save the item to a temp file, which is then (usually) later deleted by picker callbacks - Directory_Create("Exported"); + Directory_Create(FILEPATH_RAW("Exported"))); save_path.length = 0; String_Format2(&save_path, "Exported/%s%c", &args->defaultName, args->filters[0]);