Skip to content

Commit ec8b9a0

Browse files
authored
Update to latest libroot (commit 102348f) (#95)
opa334/libroot@102348f
1 parent 1e2a76d commit ec8b9a0

File tree

1 file changed

+44
-7
lines changed

1 file changed

+44
-7
lines changed

libroot/libroot.h

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,69 @@
22

33
__BEGIN_DECLS
44

5+
_Pragma("GCC visibility push(hidden)")
6+
57
const char *_Nonnull libroot_dyn_get_root_prefix(void);
68
const char *_Nonnull libroot_dyn_get_jbroot_prefix(void);
79
const char *_Nonnull libroot_dyn_get_boot_uuid(void);
810
char *_Nullable libroot_dyn_rootfspath(const char *_Nullable path, char *_Nullable resolvedPath);
911
char *_Nullable libroot_dyn_jbrootpath(const char *_Nullable path, char *_Nullable resolvedPath);
1012

13+
_Pragma("GCC visibility pop")
14+
1115
__END_DECLS
1216

17+
#define __CONVERT_PATH_CSTRING(converter, path) ({ \
18+
static char outPath[PATH_MAX]; \
19+
converter(path, outPath); \
20+
})
21+
22+
#define JBROOT_PATH_CSTRING(path) __CONVERT_PATH_CSTRING(libroot_dyn_jbrootpath, path)
23+
#define ROOTFS_PATH_CSTRING(path) __CONVERT_PATH_CSTRING(libroot_dyn_rootfspath, path)
24+
25+
#if __has_attribute(overloadable)
26+
__attribute__((__overloadable__))
27+
static inline const char *_Nullable __libroot_convert_path(char *_Nullable (*_Nonnull converter)(const char *_Nonnull, char *_Nullable), const char *_Nullable path, char *_Nonnull buf) {
28+
return converter(path, buf);
29+
}
30+
#endif /* __has_attribute(overloadable) */
31+
1332
#ifdef __OBJC__
1433

34+
#import <Foundation/Foundation.h>
35+
1536
#define __CONVERT_PATH_NSSTRING(converter, path) ({ \
1637
char tmpBuf[PATH_MAX]; \
17-
[NSString stringWithUTF8String:converter(path.fileSystemRepresentation, tmpBuf)]; \
38+
const char *converted = converter(path.fileSystemRepresentation, tmpBuf); \
39+
converted ? [NSString stringWithUTF8String:converted] : nil; \
1840
})
1941

2042
#define JBROOT_PATH_NSSTRING(path) __CONVERT_PATH_NSSTRING(libroot_dyn_jbrootpath, path)
2143
#define ROOTFS_PATH_NSSTRING(path) __CONVERT_PATH_NSSTRING(libroot_dyn_rootfspath, path)
2244

45+
#if __has_attribute(overloadable)
46+
__attribute__((__overloadable__))
47+
static inline NSString *_Nullable __libroot_convert_path(char *_Nullable (*_Nonnull converter)(const char *_Nonnull, char *_Nullable), NSString *_Nullable path, void *_Nullable const __unused buf) {
48+
return __CONVERT_PATH_NSSTRING(converter, path);
49+
}
50+
#endif /* __has_attribute(overloadable) */
51+
2352
#endif /* __OBJC__ */
2453

25-
#define __CONVERT_PATH_CSTRING(converter, path) ({ \
26-
static char outPath[PATH_MAX]; \
27-
converter(path, outPath); \
28-
})
54+
#if __has_attribute(overloadable)
2955

30-
#define JBROOT_PATH_CSTRING(path) __CONVERT_PATH_CSTRING(libroot_dyn_jbrootpath, path)
31-
#define ROOTFS_PATH_CSTRING(path) __CONVERT_PATH_CSTRING(libroot_dyn_rootfspath, path)
56+
#define __BUFFER_FOR_CHAR_P(x) \
57+
__builtin_choose_expr( \
58+
__builtin_types_compatible_p(__typeof__(*(x)), char), \
59+
({ static char buf[PATH_MAX]; buf; }), \
60+
NULL \
61+
)
62+
63+
# define JBROOT_PATH(path) __libroot_convert_path(libroot_dyn_jbrootpath, (path), __BUFFER_FOR_CHAR_P(path))
64+
# define ROOTFS_PATH(path) __libroot_convert_path(libroot_dyn_rootfspath, (path), __BUFFER_FOR_CHAR_P(path))
65+
#else
66+
# define JBROOT_PATH(path) _Pragma("GCC error \"JBROOT_PATH is not supported with this compiler, use JBROOT_PATH_CSTRING or JBROOT_PATH_NSSTRING\"") path
67+
# define ROOTFS_PATH(path) _Pragma("GCC error \"ROOTFS_PATH is not supported with this compiler, use ROOTFS_PATH_CSTRING or ROOTFS_PATH_NSSTRING\"") path
68+
#endif /* __has_attribute(overloadable) */
3269

3370
#define JBRAND libroot_dyn_get_boot_uuid()

0 commit comments

Comments
 (0)