From 88f1a1a16f851c9b8542ef68807d1f6698a41a82 Mon Sep 17 00:00:00 2001 From: Lightmann Date: Fri, 16 Feb 2024 22:54:15 -0500 Subject: [PATCH 1/8] Add libroot.h From opa334/libroot/5a8c9fc. --- LICENSE.md | 3 +++ libroot.h | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 libroot.h diff --git a/LICENSE.md b/LICENSE.md index a73524d..3df5559 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -24,6 +24,9 @@ There is no particular license on this repo. Files in this repo come from many s ### KennyTM * GraphicsServices, IOSurface, substrate2.h: [3-Clause BSD License](https://opensource.org/licenses/BSD-3-Clause) +### Opa334 +* libroot: [MIT](https://github.com/opa334/libroot/blob/main/LICENSE.md) + ### PixelFire * libcolorpicker: [MIT License](https://github.com/atomikpanda/libcolorpicker/blob/master/LICENSE.md) diff --git a/libroot.h b/libroot.h new file mode 100644 index 0000000..bd065b8 --- /dev/null +++ b/libroot.h @@ -0,0 +1,27 @@ +const char *libroot_dyn_get_root_prefix(void); +const char *libroot_dyn_get_jbroot_prefix(void); +const char *libroot_dyn_get_boot_uuid(void); +char *libroot_dyn_rootfspath(const char *path, char *resolvedPath); +char *libroot_dyn_jbrootpath(const char *path, char *resolvedPath); + +#ifdef __OBJC__ + +#define __CONVERT_PATH_NSSTRING(converter, path) ({ \ + char tmpBuf[PATH_MAX]; \ + [NSString stringWithUTF8String:converter(path.fileSystemRepresentation, tmpBuf)]; \ +}) + +#define JBROOT_PATH_NSSTRING(path) __CONVERT_PATH_NSSTRING(libroot_dyn_jbrootpath, path) +#define ROOTFS_PATH_NSSTRING(path) __CONVERT_PATH_NSSTRING(libroot_dyn_rootfspath, path) + +#endif /* __OBJC__ */ + +#define __CONVERT_PATH_CSTRING(converter, path) ({ \ + static char outPath[PATH_MAX]; \ + converter(path, outPath); \ +}) + +#define JBROOT_PATH_CSTRING(path) __CONVERT_PATH_CSTRING(libroot_dyn_jbrootpath, path) +#define ROOTFS_PATH_CSTRING(path) __CONVERT_PATH_CSTRING(libroot_dyn_rootfspath, path) + +#define JBRAND libroot_dyn_get_boot_uuid() From ad2519080c684fc5cadd435a3a52535b692f024b Mon Sep 17 00:00:00 2001 From: Lightmann Date: Fri, 16 Feb 2024 23:09:31 -0500 Subject: [PATCH 2/8] Update rootless.h for libroot --- rootless.h | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/rootless.h b/rootless.h index a941637..c997514 100644 --- a/rootless.h +++ b/rootless.h @@ -1,24 +1,22 @@ -#include -#include +// TODO: remove this file +// #include +// #include +#include "libroot.h" -#ifdef XINA_SUPPORT // Only define this for rootful compilations that need support for xina -#define ROOT_PATH(cPath) !access("/var/LIY", F_OK) ? "/var/jb" cPath : cPath -#define ROOT_PATH_NS(path) !access("/var/LIY", F_OK) ? @"/var/jb" path : path -#define ROOT_PATH_NS_VAR(path) !access("/var/LIY", F_OK) ? [@"/var/jb" stringByAppendingPathComponent:path] : path -#define ROOT_PATH_VAR(path) !access("/var/LIY", F_OK) ? ({ \ - char outPath[PATH_MAX]; \ - strlcpy(outPath, "/var/jb", PATH_MAX); \ - strlcat(outPath, path, PATH_MAX); \ - outPath; \ -}) : path -#else -#define ROOT_PATH(cPath) THEOS_PACKAGE_INSTALL_PREFIX cPath -#define ROOT_PATH_NS(path) @THEOS_PACKAGE_INSTALL_PREFIX path -#define ROOT_PATH_NS_VAR(path) [@THEOS_PACKAGE_INSTALL_PREFIX stringByAppendingPathComponent:path] -#define ROOT_PATH_VAR(path) sizeof(THEOS_PACKAGE_INSTALL_PREFIX) > 1 ? ({ \ - char outPath[PATH_MAX]; \ - strlcpy(outPath, THEOS_PACKAGE_INSTALL_PREFIX, PATH_MAX); \ - strlcat(outPath, path, PATH_MAX); \ - outPath; \ -}) : path -#endif \ No newline at end of file +#ifdef XINA_SUPPORT +_Pragma("message(\"'XINA_SUPPORT' is deprecated. libroot will now handle this for you.\")") +#endif +// #define ROOT_PATH(cPath) THEOS_PACKAGE_INSTALL_PREFIX cPath +// #define ROOT_PATH_VAR(path) sizeof(THEOS_PACKAGE_INSTALL_PREFIX) > 1 ? ({ \ +// char outPath[PATH_MAX]; \ +// strlcpy(outPath, THEOS_PACKAGE_INSTALL_PREFIX, PATH_MAX); \ +// strlcat(outPath, path, PATH_MAX); \ +// outPath; \ +// }) : path +#define ROOT_PATH(cPath) _Pragma("message(\"'ROOT_PATH' is deprecated. Please import libroot.h and use 'JBROOT_PATH_CSTRING' instead.\")") JBROOT_PATH_CSTRING(cPath) +#define ROOT_PATH_VAR(path) _Pragma("message(\"'ROOT_PATH_VAR' is deprecated. Please import libroot.h and use 'JBROOT_PATH_CSTRING' instead.\")") JBROOT_PATH_CSTRING(path) + +// #define ROOT_PATH_NS(path) @THEOS_PACKAGE_INSTALL_PREFIX path +// #define ROOT_PATH_NS_VAR(path) [@THEOS_PACKAGE_INSTALL_PREFIX stringByAppendingPathComponent:path] +#define ROOT_PATH_NS(path) _Pragma("message(\"'ROOT_PATH_NS' is deprecated. Please import libroot.h and use 'JBROOT_PATH_NSSTRING' instead.\")") JBROOT_PATH_NSSTRING(path) +#define ROOT_PATH_NS_VAR(path) _Pragma("message(\"'ROOT_PATH_NS_VAR' is deprecated. Please import libroot.h and use 'JBROOT_PATH_NSSTRING' instead.\")") JBROOT_PATH_NSSTRING(path) From a7226d229ccaea7cb6447ba456361be9bc82ac0a Mon Sep 17 00:00:00 2001 From: Leptos Date: Sat, 17 Feb 2024 11:22:20 -0800 Subject: [PATCH 3/8] Move libroot.h to libroot/libroot.h, added module support --- libroot.h | 28 +--------------------------- libroot/libroot.h | 29 +++++++++++++++++++++++++++++ libroot/module.modulemap | 6 ++++++ rootless.h | 26 +++++++++----------------- 4 files changed, 45 insertions(+), 44 deletions(-) mode change 100644 => 120000 libroot.h create mode 100644 libroot/libroot.h create mode 100644 libroot/module.modulemap diff --git a/libroot.h b/libroot.h deleted file mode 100644 index bd065b8..0000000 --- a/libroot.h +++ /dev/null @@ -1,27 +0,0 @@ -const char *libroot_dyn_get_root_prefix(void); -const char *libroot_dyn_get_jbroot_prefix(void); -const char *libroot_dyn_get_boot_uuid(void); -char *libroot_dyn_rootfspath(const char *path, char *resolvedPath); -char *libroot_dyn_jbrootpath(const char *path, char *resolvedPath); - -#ifdef __OBJC__ - -#define __CONVERT_PATH_NSSTRING(converter, path) ({ \ - char tmpBuf[PATH_MAX]; \ - [NSString stringWithUTF8String:converter(path.fileSystemRepresentation, tmpBuf)]; \ -}) - -#define JBROOT_PATH_NSSTRING(path) __CONVERT_PATH_NSSTRING(libroot_dyn_jbrootpath, path) -#define ROOTFS_PATH_NSSTRING(path) __CONVERT_PATH_NSSTRING(libroot_dyn_rootfspath, path) - -#endif /* __OBJC__ */ - -#define __CONVERT_PATH_CSTRING(converter, path) ({ \ - static char outPath[PATH_MAX]; \ - converter(path, outPath); \ -}) - -#define JBROOT_PATH_CSTRING(path) __CONVERT_PATH_CSTRING(libroot_dyn_jbrootpath, path) -#define ROOTFS_PATH_CSTRING(path) __CONVERT_PATH_CSTRING(libroot_dyn_rootfspath, path) - -#define JBRAND libroot_dyn_get_boot_uuid() diff --git a/libroot.h b/libroot.h new file mode 120000 index 0000000..5ded31b --- /dev/null +++ b/libroot.h @@ -0,0 +1 @@ +libroot/libroot.h \ No newline at end of file diff --git a/libroot/libroot.h b/libroot/libroot.h new file mode 100644 index 0000000..b46e60a --- /dev/null +++ b/libroot/libroot.h @@ -0,0 +1,29 @@ +#include + +const char *libroot_dyn_get_root_prefix(void); +const char *libroot_dyn_get_jbroot_prefix(void); +const char *libroot_dyn_get_boot_uuid(void); +char *libroot_dyn_rootfspath(const char *path, char *resolvedPath); +char *libroot_dyn_jbrootpath(const char *path, char *resolvedPath); + +#ifdef __OBJC__ + +#define __CONVERT_PATH_NSSTRING(converter, path) ({ \ + char tmpBuf[PATH_MAX]; \ + [NSString stringWithUTF8String:converter(path.fileSystemRepresentation, tmpBuf)]; \ +}) + +#define JBROOT_PATH_NSSTRING(path) __CONVERT_PATH_NSSTRING(libroot_dyn_jbrootpath, path) +#define ROOTFS_PATH_NSSTRING(path) __CONVERT_PATH_NSSTRING(libroot_dyn_rootfspath, path) + +#endif /* __OBJC__ */ + +#define __CONVERT_PATH_CSTRING(converter, path) ({ \ + static char outPath[PATH_MAX]; \ + converter(path, outPath); \ +}) + +#define JBROOT_PATH_CSTRING(path) __CONVERT_PATH_CSTRING(libroot_dyn_jbrootpath, path) +#define ROOTFS_PATH_CSTRING(path) __CONVERT_PATH_CSTRING(libroot_dyn_rootfspath, path) + +#define JBRAND libroot_dyn_get_boot_uuid() diff --git a/libroot/module.modulemap b/libroot/module.modulemap new file mode 100644 index 0000000..9e16196 --- /dev/null +++ b/libroot/module.modulemap @@ -0,0 +1,6 @@ +module libroot { + umbrella header "libroot.h" + link "root" + + export * +} diff --git a/rootless.h b/rootless.h index c997514..8412eb2 100644 --- a/rootless.h +++ b/rootless.h @@ -1,22 +1,14 @@ -// TODO: remove this file -// #include -// #include -#include "libroot.h" +#include #ifdef XINA_SUPPORT _Pragma("message(\"'XINA_SUPPORT' is deprecated. libroot will now handle this for you.\")") #endif -// #define ROOT_PATH(cPath) THEOS_PACKAGE_INSTALL_PREFIX cPath -// #define ROOT_PATH_VAR(path) sizeof(THEOS_PACKAGE_INSTALL_PREFIX) > 1 ? ({ \ -// char outPath[PATH_MAX]; \ -// strlcpy(outPath, THEOS_PACKAGE_INSTALL_PREFIX, PATH_MAX); \ -// strlcat(outPath, path, PATH_MAX); \ -// outPath; \ -// }) : path -#define ROOT_PATH(cPath) _Pragma("message(\"'ROOT_PATH' is deprecated. Please import libroot.h and use 'JBROOT_PATH_CSTRING' instead.\")") JBROOT_PATH_CSTRING(cPath) -#define ROOT_PATH_VAR(path) _Pragma("message(\"'ROOT_PATH_VAR' is deprecated. Please import libroot.h and use 'JBROOT_PATH_CSTRING' instead.\")") JBROOT_PATH_CSTRING(path) -// #define ROOT_PATH_NS(path) @THEOS_PACKAGE_INSTALL_PREFIX path -// #define ROOT_PATH_NS_VAR(path) [@THEOS_PACKAGE_INSTALL_PREFIX stringByAppendingPathComponent:path] -#define ROOT_PATH_NS(path) _Pragma("message(\"'ROOT_PATH_NS' is deprecated. Please import libroot.h and use 'JBROOT_PATH_NSSTRING' instead.\")") JBROOT_PATH_NSSTRING(path) -#define ROOT_PATH_NS_VAR(path) _Pragma("message(\"'ROOT_PATH_NS_VAR' is deprecated. Please import libroot.h and use 'JBROOT_PATH_NSSTRING' instead.\")") JBROOT_PATH_NSSTRING(path) +// compatibility header +// use libroot/libroot.h directly in the future + +#define ROOT_PATH(cPath) JBROOT_PATH_CSTRING(cPath) +#define ROOT_PATH_VAR(path) JBROOT_PATH_CSTRING(path) + +#define ROOT_PATH_NS(path) JBROOT_PATH_NSSTRING(path) +#define ROOT_PATH_NS_VAR(path) JBROOT_PATH_NSSTRING(path) From cc836c22b8b4d777d985d6e5a499ae63328d9ca2 Mon Sep 17 00:00:00 2001 From: Leptos Date: Sat, 17 Feb 2024 11:22:44 -0800 Subject: [PATCH 4/8] Add nullability specifiers to libroot.h --- libroot/libroot.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libroot/libroot.h b/libroot/libroot.h index b46e60a..42d2850 100644 --- a/libroot/libroot.h +++ b/libroot/libroot.h @@ -1,10 +1,10 @@ #include -const char *libroot_dyn_get_root_prefix(void); -const char *libroot_dyn_get_jbroot_prefix(void); -const char *libroot_dyn_get_boot_uuid(void); -char *libroot_dyn_rootfspath(const char *path, char *resolvedPath); -char *libroot_dyn_jbrootpath(const char *path, char *resolvedPath); +const char *_Nonnull libroot_dyn_get_root_prefix(void); +const char *_Nonnull libroot_dyn_get_jbroot_prefix(void); +const char *_Nonnull libroot_dyn_get_boot_uuid(void); +char *_Nullable libroot_dyn_rootfspath(const char *_Nullable path, char *_Nullable resolvedPath); +char *_Nullable libroot_dyn_jbrootpath(const char *_Nullable path, char *_Nullable resolvedPath); #ifdef __OBJC__ From 8b5ce094a2305bb754f6803efeea63b0a0d3bc0c Mon Sep 17 00:00:00 2001 From: Leptos Date: Sat, 17 Feb 2024 11:38:20 -0800 Subject: [PATCH 5/8] revert rootless.h changes --- rootless.h | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/rootless.h b/rootless.h index 8412eb2..fa465bb 100644 --- a/rootless.h +++ b/rootless.h @@ -1,14 +1,22 @@ +// TODO: remove this file +// #include +// #include #include #ifdef XINA_SUPPORT _Pragma("message(\"'XINA_SUPPORT' is deprecated. libroot will now handle this for you.\")") #endif +// #define ROOT_PATH(cPath) THEOS_PACKAGE_INSTALL_PREFIX cPath +// #define ROOT_PATH_VAR(path) sizeof(THEOS_PACKAGE_INSTALL_PREFIX) > 1 ? ({ \ +// char outPath[PATH_MAX]; \ +// strlcpy(outPath, THEOS_PACKAGE_INSTALL_PREFIX, PATH_MAX); \ +// strlcat(outPath, path, PATH_MAX); \ +// outPath; \ +// }) : path +#define ROOT_PATH(cPath) _Pragma("message(\"'ROOT_PATH' is deprecated. Please import libroot.h and use 'JBROOT_PATH_CSTRING' instead.\")") JBROOT_PATH_CSTRING(cPath) +#define ROOT_PATH_VAR(path) _Pragma("message(\"'ROOT_PATH_VAR' is deprecated. Please import libroot.h and use 'JBROOT_PATH_CSTRING' instead.\")") JBROOT_PATH_CSTRING(path) -// compatibility header -// use libroot/libroot.h directly in the future - -#define ROOT_PATH(cPath) JBROOT_PATH_CSTRING(cPath) -#define ROOT_PATH_VAR(path) JBROOT_PATH_CSTRING(path) - -#define ROOT_PATH_NS(path) JBROOT_PATH_NSSTRING(path) -#define ROOT_PATH_NS_VAR(path) JBROOT_PATH_NSSTRING(path) +// #define ROOT_PATH_NS(path) @THEOS_PACKAGE_INSTALL_PREFIX path +// #define ROOT_PATH_NS_VAR(path) [@THEOS_PACKAGE_INSTALL_PREFIX stringByAppendingPathComponent:path] +#define ROOT_PATH_NS(path) _Pragma("message(\"'ROOT_PATH_NS' is deprecated. Please import libroot.h and use 'JBROOT_PATH_NSSTRING' instead.\")") JBROOT_PATH_NSSTRING(path) +#define ROOT_PATH_NS_VAR(path) _Pragma("message(\"'ROOT_PATH_NS_VAR' is deprecated. Please import libroot.h and use 'JBROOT_PATH_NSSTRING' instead.\")") JBROOT_PATH_NSSTRING(path) From 6bd670ba0bcb40a5f5067f253880b6982be30202 Mon Sep 17 00:00:00 2001 From: Lightmann Date: Sun, 18 Feb 2024 16:27:15 -0500 Subject: [PATCH 6/8] Out with the old, in with the new --- rootless.h | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/rootless.h b/rootless.h index fa465bb..f50a2fc 100644 --- a/rootless.h +++ b/rootless.h @@ -1,22 +1,12 @@ // TODO: remove this file -// #include -// #include #include #ifdef XINA_SUPPORT _Pragma("message(\"'XINA_SUPPORT' is deprecated. libroot will now handle this for you.\")") #endif -// #define ROOT_PATH(cPath) THEOS_PACKAGE_INSTALL_PREFIX cPath -// #define ROOT_PATH_VAR(path) sizeof(THEOS_PACKAGE_INSTALL_PREFIX) > 1 ? ({ \ -// char outPath[PATH_MAX]; \ -// strlcpy(outPath, THEOS_PACKAGE_INSTALL_PREFIX, PATH_MAX); \ -// strlcat(outPath, path, PATH_MAX); \ -// outPath; \ -// }) : path + #define ROOT_PATH(cPath) _Pragma("message(\"'ROOT_PATH' is deprecated. Please import libroot.h and use 'JBROOT_PATH_CSTRING' instead.\")") JBROOT_PATH_CSTRING(cPath) #define ROOT_PATH_VAR(path) _Pragma("message(\"'ROOT_PATH_VAR' is deprecated. Please import libroot.h and use 'JBROOT_PATH_CSTRING' instead.\")") JBROOT_PATH_CSTRING(path) -// #define ROOT_PATH_NS(path) @THEOS_PACKAGE_INSTALL_PREFIX path -// #define ROOT_PATH_NS_VAR(path) [@THEOS_PACKAGE_INSTALL_PREFIX stringByAppendingPathComponent:path] #define ROOT_PATH_NS(path) _Pragma("message(\"'ROOT_PATH_NS' is deprecated. Please import libroot.h and use 'JBROOT_PATH_NSSTRING' instead.\")") JBROOT_PATH_NSSTRING(path) #define ROOT_PATH_NS_VAR(path) _Pragma("message(\"'ROOT_PATH_NS_VAR' is deprecated. Please import libroot.h and use 'JBROOT_PATH_NSSTRING' instead.\")") JBROOT_PATH_NSSTRING(path) From 5b9cd2955cee7d6def712d73b988a7f8987e579b Mon Sep 17 00:00:00 2001 From: Lightmann Date: Sun, 18 Feb 2024 16:39:14 -0500 Subject: [PATCH 7/8] We're back! --- rootless.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/rootless.h b/rootless.h index f50a2fc..a7fd868 100644 --- a/rootless.h +++ b/rootless.h @@ -1,12 +1,11 @@ -// TODO: remove this file #include #ifdef XINA_SUPPORT _Pragma("message(\"'XINA_SUPPORT' is deprecated. libroot will now handle this for you.\")") #endif -#define ROOT_PATH(cPath) _Pragma("message(\"'ROOT_PATH' is deprecated. Please import libroot.h and use 'JBROOT_PATH_CSTRING' instead.\")") JBROOT_PATH_CSTRING(cPath) -#define ROOT_PATH_VAR(path) _Pragma("message(\"'ROOT_PATH_VAR' is deprecated. Please import libroot.h and use 'JBROOT_PATH_CSTRING' instead.\")") JBROOT_PATH_CSTRING(path) +#define ROOT_PATH(cPath) JBROOT_PATH_CSTRING(cPath) +#define ROOT_PATH_VAR(cPath) JBROOT_PATH_CSTRING(cPath) -#define ROOT_PATH_NS(path) _Pragma("message(\"'ROOT_PATH_NS' is deprecated. Please import libroot.h and use 'JBROOT_PATH_NSSTRING' instead.\")") JBROOT_PATH_NSSTRING(path) -#define ROOT_PATH_NS_VAR(path) _Pragma("message(\"'ROOT_PATH_NS_VAR' is deprecated. Please import libroot.h and use 'JBROOT_PATH_NSSTRING' instead.\")") JBROOT_PATH_NSSTRING(path) +#define ROOT_PATH_NS(nsPath) JBROOT_PATH_NSSTRING(nsPath) +#define ROOT_PATH_NS_VAR(nsPath) JBROOT_PATH_NSSTRING(nsPath) From 396dfd47a5cd674e2449e7621178a5c732576038 Mon Sep 17 00:00:00 2001 From: Leptos Date: Sat, 24 Feb 2024 16:52:38 -0800 Subject: [PATCH 8/8] Extern functions for cpp --- libroot/libroot.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libroot/libroot.h b/libroot/libroot.h index 42d2850..293a7f1 100644 --- a/libroot/libroot.h +++ b/libroot/libroot.h @@ -1,11 +1,15 @@ #include +__BEGIN_DECLS + const char *_Nonnull libroot_dyn_get_root_prefix(void); const char *_Nonnull libroot_dyn_get_jbroot_prefix(void); const char *_Nonnull libroot_dyn_get_boot_uuid(void); char *_Nullable libroot_dyn_rootfspath(const char *_Nullable path, char *_Nullable resolvedPath); char *_Nullable libroot_dyn_jbrootpath(const char *_Nullable path, char *_Nullable resolvedPath); +__END_DECLS + #ifdef __OBJC__ #define __CONVERT_PATH_NSSTRING(converter, path) ({ \