summaryrefslogtreecommitdiffstats
path: root/src/fakerw/fake.cpp
diff options
context:
space:
mode:
authorerorcun <erayorcunus@gmail.com>2020-07-28 16:41:49 +0200
committerGitHub <noreply@github.com>2020-07-28 16:41:49 +0200
commite47eaa1425176e21d684b3bcb87c198dd9c5b05f (patch)
treeb3925fee0ec654339175c156e8c9733886517998 /src/fakerw/fake.cpp
parentcollision fixes (diff)
parentFix casepath chaos (diff)
downloadre3-e47eaa1425176e21d684b3bcb87c198dd9c5b05f.tar
re3-e47eaa1425176e21d684b3bcb87c198dd9c5b05f.tar.gz
re3-e47eaa1425176e21d684b3bcb87c198dd9c5b05f.tar.bz2
re3-e47eaa1425176e21d684b3bcb87c198dd9c5b05f.tar.lz
re3-e47eaa1425176e21d684b3bcb87c198dd9c5b05f.tar.xz
re3-e47eaa1425176e21d684b3bcb87c198dd9c5b05f.tar.zst
re3-e47eaa1425176e21d684b3bcb87c198dd9c5b05f.zip
Diffstat (limited to 'src/fakerw/fake.cpp')
-rw-r--r--src/fakerw/fake.cpp62
1 files changed, 29 insertions, 33 deletions
diff --git a/src/fakerw/fake.cpp b/src/fakerw/fake.cpp
index d4417a7f..7d563d77 100644
--- a/src/fakerw/fake.cpp
+++ b/src/fakerw/fake.cpp
@@ -375,23 +375,19 @@ RwStream *RwStreamOpen(RwStreamType type, RwStreamAccessType accessType, const v
file = rwNewT(StreamFile, 1, 0);
memcpy(file, &fakefile, sizeof(StreamFile));
#ifndef _WIN32
- // Be case-insensitive and fix backslashes (from https://github.com/OneSadCookie/fcaseopen/)
- FILE* first = fopen((char*)pData, "r");
- char *r;
- if (!first) {
- r = (char*)alloca(strlen((char*)pData) + 4);
- // Use default path(and pass error handling to librw) if we can't find any match
- if (!casepath((char*)pData, r))
- r = (char*)pData;
+ char *r = casepath((char*)pData);
+ if (r) {
+ if (file->open((char*)r, mode)) {
+ free(r);
+ return file;
+ }
+ free(r);
} else
- fclose(first);
-
- if(file->open((char*)r, mode))
- return file;
-#else
- if(file->open((char*)pData, mode))
- return file;
#endif
+ {
+ if (file->open((char*)pData, mode))
+ return file;
+ }
rwFree(file);
return nil;
}
@@ -859,15 +855,14 @@ RwImage *
RtBMPImageWrite(RwImage *image, const RwChar *imageName)
{
#ifndef _WIN32
- char *r = nil;
- FILE *valid = fopen((char *)imageName, "r");
- if(!valid) {
- char *r = (char *)alloca(strlen((char *)imageName) + 4);
- // Use default path(and pass error handling to librw) if we can't find any match
- if(!casepath((char *)imageName, r)) r = (char *)imageName;
- } else
- fclose(valid);
- rw::writeBMP(image, r);
+ char *r = casepath(imageName);
+ if (r) {
+ rw::writeBMP(image, r);
+ free(r);
+ } else {
+ rw::writeBMP(image, imageName);
+ }
+
#else
rw::writeBMP(image, imageName);
#endif
@@ -877,15 +872,16 @@ RwImage *
RtBMPImageRead(const RwChar *imageName)
{
#ifndef _WIN32
- char *r = nil;
- FILE *valid = fopen((char *)imageName, "r");
- if(!valid) {
- r = (char *)alloca(strlen((char *)imageName) + 4);
- // Use default path(and pass error handling to librw) if we can't find any match
- if(!casepath((char *)imageName, r)) r = (char *)imageName;
- } else
- fclose(valid);
- return rw::readBMP(r);
+ RwImage *image;
+ char *r = casepath(imageName);
+ if (r) {
+ image = rw::readBMP(r);
+ free(r);
+ } else {
+ image = rw::readBMP(imageName);
+ }
+ return image;
+
#else
return rw::readBMP(imageName);
#endif