[physfs] [PATCH V2]: 3DS support

Vladimir 'phcoder' Serbinenko phcoder at gmail.com
Wed Mar 18 20:51:49 EDT 2020


Sorry, old patch didn't have correct guards

commit 39c9f757cc93260de3608bf2e12c37d3b8876436
Author: Vladimir Serbinenko <phcoder at google.com>
Date:   Tue Mar 17 14:04:21 2020 +0100

    Support for 3DS

diff --git a/src/physfs_platform_posix.c b/src/physfs_platform_posix.c
index fa2159c..139591e 100644
--- a/src/physfs_platform_posix.c
+++ b/src/physfs_platform_posix.c
@@ -23,6 +23,47 @@
 #include <fcntl.h>
 #include <pthread.h>

+#ifdef _3DS
+#include <3ds/thread.h>
+#include <3ds/synchronization.h>
+#include <3ds/svc.h>
+#include <time.h>
+#include <errno.h>
+
+typedef LightLock  pthread_mutex_t;
+typedef Thread     pthread_t;
+
+static inline int pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+   return LightLock_TryLock(mutex);
+}
+
+static inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+   LightLock_Unlock(mutex);
+   return 0;
+}
+
+static inline pthread_t pthread_self(void)
+{
+   return threadGetCurrent();
+}
+
+static inline int pthread_mutex_init(pthread_mutex_t *mutex,
+      const void *attr)
+{
+   LightLock_Init(mutex);
+   return 0;
+}
+
+static inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
+{
+   /*Nothing to destroy*/
+   return 0;
+}
+
+#endif
+
 #include "physfs_internal.h"


@@ -58,6 +99,7 @@ static inline PHYSFS_ErrorCode errcodeFromErrno(void)
 } /* errcodeFromErrno */


+#ifndef PHYSFS_HARDCODED_HOME
 static char *getUserDirByUID(void)
 {
     uid_t uid = getuid();
@@ -83,10 +125,14 @@ static char *getUserDirByUID(void)

     return retval;
 } /* getUserDirByUID */
+#endif


 char *__PHYSFS_platformCalcUserDir(void)
 {
+#ifdef PHYSFS_HARDCODED_HOME
+    return strdup(PHYSFS_HARDCODED_HOME);
+#else
     char *retval = NULL;
     char *envr = getenv("HOME");

@@ -115,6 +161,7 @@ char *__PHYSFS_platformCalcUserDir(void)
         retval = getUserDirByUID();

     return retval;
+#endif
 } /* __PHYSFS_platformCalcUserDir */


diff --git a/src/physfs_platform_unix.c b/src/physfs_platform_unix.c
index 10d93a7..495bc27 100644
--- a/src/physfs_platform_unix.c
+++ b/src/physfs_platform_unix.c
@@ -214,6 +214,7 @@ static char *findBinaryInPath(const char *bin, char *envr)
 } /* findBinaryInPath */


+#ifndef PHYSFS_HARDCODED_BASE_DIR
 static char *readSymLink(const char *path)
 {
     ssize_t len = 64;
@@ -244,10 +245,13 @@ static char *readSymLink(const char *path)
         allocator.Free(retval);
     return NULL;
 } /* readSymLink */
-
+#endif

 char *__PHYSFS_platformCalcBaseDir(const char *argv0)
 {
+#ifdef PHYSFS_HARDCODED_BASE_DIR
+    return strdup (PHYSFS_HARDCODED_BASE_DIR);
+#else
     char *retval = NULL;
     const char *envr = NULL;

@@ -329,6 +333,7 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0)
     } /* if */

     return retval;
+#endif
 } /* __PHYSFS_platformCalcBaseDir */


diff --git a/src/physfs_platforms.h b/src/physfs_platforms.h
index d4e4bfd..96d5854 100644
--- a/src/physfs_platforms.h
+++ b/src/physfs_platforms.h
@@ -72,6 +72,13 @@
 #elif defined(unix) || defined(__unix__)
 #  define PHYSFS_PLATFORM_UNIX 1
 #  define PHYSFS_PLATFORM_POSIX 1
+#elif defined(_3DS)
+#  define PHYSFS_NO_CDROM_SUPPORT 1
+#  define PHYSFS_PLATFORM_UNIX 1
+#  define PHYSFS_PLATFORM_POSIX 1
+#  define PHYSFS_HARDCODED_HOME "sdmc:/"
+#  define PHYSFS_HARDCODED_BASE_DIR "sdmc:/"
+#  define lstat stat
 #else
 #  error Unknown platform.
 #endif


-- 
Regards
Vladimir 'phcoder' Serbinenko
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 3ds-physfs.patch
Type: application/octet-stream
Size: 3323 bytes
Desc: not available
URL: <http://icculus.org/pipermail/physfs/attachments/20200319/44025883/attachment.obj>


More information about the physfs mailing list