summaryrefslogtreecommitdiffstats
path: root/src/skel/crossplatform.cpp
diff options
context:
space:
mode:
authorAdrian Graber <adrian@adriangraber.com>2021-07-13 01:11:42 +0200
committerAdrian Graber <adrian@adriangraber.com>2021-07-13 01:18:49 +0200
commit6665b16ba279f9d92c5a5b2ddc62dd584e20b581 (patch)
tree1afbad268cc33b440c406ffa254304b3f819147c /src/skel/crossplatform.cpp
parentdisable USE_CUTSCENE_SHADOW_FOR_PED if COMPATIBLE_SAVES isn't defined (diff)
downloadre3-6665b16ba279f9d92c5a5b2ddc62dd584e20b581.tar
re3-6665b16ba279f9d92c5a5b2ddc62dd584e20b581.tar.gz
re3-6665b16ba279f9d92c5a5b2ddc62dd584e20b581.tar.bz2
re3-6665b16ba279f9d92c5a5b2ddc62dd584e20b581.tar.lz
re3-6665b16ba279f9d92c5a5b2ddc62dd584e20b581.tar.xz
re3-6665b16ba279f9d92c5a5b2ddc62dd584e20b581.tar.zst
re3-6665b16ba279f9d92c5a5b2ddc62dd584e20b581.zip
Diffstat (limited to 'src/skel/crossplatform.cpp')
-rw-r--r--src/skel/crossplatform.cpp146
1 files changed, 145 insertions, 1 deletions
diff --git a/src/skel/crossplatform.cpp b/src/skel/crossplatform.cpp
index f7016b21..58ab7920 100644
--- a/src/skel/crossplatform.cpp
+++ b/src/skel/crossplatform.cpp
@@ -198,6 +198,20 @@ char* casepath(char const* path, bool checkPathFirst)
size_t rl = 0;
DIR* d;
+ char* c;
+
+ #if defined(__SWITCH__) || defined(PSP2)
+ if( (c = strstr(p, ":/")) != NULL) // scheme used by some environments, eg. switch, vita
+ {
+ size_t deviceNameOffset = c - p + 3;
+ char* deviceNamePath = (char*)alloca(deviceNameOffset + 1);
+ strlcpy(deviceNamePath, p, deviceNameOffset);
+ deviceNamePath[deviceNameOffset] = 0;
+ d = opendir(deviceNamePath);
+ p = c + 1;
+ }
+ else
+ #endif
if (p[0] == '/' || p[0] == '\\')
{
d = opendir("/");
@@ -212,7 +226,7 @@ char* casepath(char const* path, bool checkPathFirst)
bool cantProceed = false; // just convert slashes in what's left in string, don't correct case of letters(because we can't)
bool mayBeTrailingSlash = false;
- char* c;
+
while (c = strsep(&p, "/\\"))
{
// May be trailing slash(allow), slash at the start(avoid), or multiple slashes(avoid)
@@ -293,3 +307,133 @@ char *_strdate(char *buf) {
return strdate(buf);
}
#endif
+
+#ifdef __SWITCH__
+/* Taken from glibc */
+char *realpath(const char *name, char *resolved)
+{
+ char *rpath, *dest = NULL;
+ const char *start, *end, *rpath_limit;
+ long int path_max;
+
+ /* As per Single Unix Specification V2 we must return an error if
+ either parameter is a null pointer. We extend this to allow
+ the RESOLVED parameter to be NULL in case the we are expected to
+ allocate the room for the return value. */
+ if (!name)
+ return NULL;
+
+ /* As per Single Unix Specification V2 we must return an error if
+ the name argument points to an empty string. */
+ if (name[0] == '\0')
+ return NULL;
+
+#ifdef PATH_MAX
+ path_max = PATH_MAX;
+#else
+ path_max = pathconf(name, _PC_PATH_MAX);
+ if (path_max <= 0)
+ path_max = 1024;
+#endif
+
+ if (!resolved)
+ {
+ rpath = (char*)malloc(path_max);
+ if (!rpath)
+ return NULL;
+ }
+ else
+ rpath = resolved;
+ rpath_limit = rpath + path_max;
+
+ if (name[0] != '/')
+ {
+ if (!getcwd(rpath, path_max))
+ {
+ rpath[0] = '\0';
+ goto error;
+ }
+ dest = (char*)memchr(rpath, '\0', path_max);
+ }
+ else
+ {
+ rpath[0] = '/';
+ dest = rpath + 1;
+ }
+
+ for (start = end = name; *start; start = end)
+ {
+ /* Skip sequence of multiple path-separators. */
+ while (*start == '/')
+ ++start;
+
+ /* Find end of path component. */
+ for (end = start; *end && *end != '/'; ++end)
+ /* Nothing. */;
+
+ if (end - start == 0)
+ break;
+ else if (end - start == 1 && start[0] == '.')
+ /* nothing */;
+ else if (end - start == 2 && start[0] == '.' && start[1] == '.')
+ {
+ /* Back up to previous component, ignore if at root already. */
+ if (dest > rpath + 1)
+ while ((--dest)[-1] != '/')
+ ;
+ }
+ else
+ {
+ size_t new_size;
+
+ if (dest[-1] != '/')
+ *dest++ = '/';
+
+ if (dest + (end - start) >= rpath_limit)
+ {
+ ptrdiff_t dest_offset = dest - rpath;
+ char *new_rpath;
+
+ if (resolved)
+ {
+ if (dest > rpath + 1)
+ dest--;
+ *dest = '\0';
+ goto error;
+ }
+ new_size = rpath_limit - rpath;
+ if (end - start + 1 > path_max)
+ new_size += end - start + 1;
+ else
+ new_size += path_max;
+ new_rpath = (char *)realloc(rpath, new_size);
+ if (!new_rpath)
+ goto error;
+ rpath = new_rpath;
+ rpath_limit = rpath + new_size;
+
+ dest = rpath + dest_offset;
+ }
+
+ dest = (char*)memcpy(dest, start, end - start);
+ *dest = '\0';
+ }
+ }
+ if (dest > rpath + 1 && dest[-1] == '/')
+ --dest;
+ *dest = '\0';
+
+ return rpath;
+
+error:
+ if (!resolved)
+ free(rpath);
+ return NULL;
+}
+
+ssize_t readlink (const char * __path, char * __buf, size_t __buflen)
+{
+ errno = ENOSYS;
+ return -1;
+}
+#endif