Skip to content

Commit

Permalink
Merge pull request #91 from L1ghtmann/master
Browse files Browse the repository at this point in the history
Add libroot.h and update rootless.h for rootless v2
  • Loading branch information
uroboro authored Mar 2, 2024
2 parents 3f40f10 + 396dfd4 commit 47b92fd
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 23 deletions.
3 changes: 3 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions libroot.h
33 changes: 33 additions & 0 deletions libroot/libroot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <sys/syslimits.h>

__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) ({ \
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()
6 changes: 6 additions & 0 deletions libroot/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module libroot {
umbrella header "libroot.h"
link "root"

export *
}
33 changes: 10 additions & 23 deletions rootless.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
#include <sys/syslimits.h>
#include <unistd.h>
#include <libroot/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
#ifdef XINA_SUPPORT
_Pragma("message(\"'XINA_SUPPORT' is deprecated. libroot will now handle this for you.\")")
#endif

#define ROOT_PATH(cPath) JBROOT_PATH_CSTRING(cPath)
#define ROOT_PATH_VAR(cPath) JBROOT_PATH_CSTRING(cPath)

#define ROOT_PATH_NS(nsPath) JBROOT_PATH_NSSTRING(nsPath)
#define ROOT_PATH_NS_VAR(nsPath) JBROOT_PATH_NSSTRING(nsPath)

0 comments on commit 47b92fd

Please sign in to comment.