summaryrefslogtreecommitdiffstats
path: root/src/common/apple/cf_helpers.h
diff options
context:
space:
mode:
authorsumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
committersumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
commit76424950e373d3b04ac3dd13019151bfba3e8423 (patch)
tree4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/common/apple/cf_helpers.h
Add the files
Diffstat (limited to 'src/common/apple/cf_helpers.h')
-rw-r--r--src/common/apple/cf_helpers.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/common/apple/cf_helpers.h b/src/common/apple/cf_helpers.h
new file mode 100644
index 0000000..a929f03
--- /dev/null
+++ b/src/common/apple/cf_helpers.h
@@ -0,0 +1,43 @@
+#pragma once
+
+#include "fastfetch.h"
+#include <CoreFoundation/CoreFoundation.h>
+#include <IOKit/IOKitLib.h>
+
+// Return error info if failed, NULL otherwise
+const char* ffCfStrGetString(CFTypeRef cf, FFstrbuf* result);
+const char* ffCfNumGetInt(CFTypeRef cf, int32_t* result);
+const char* ffCfNumGetInt64(CFTypeRef cf, int64_t* result);
+const char* ffCfNumGetDouble(CFTypeRef cf, double* result);
+const char* ffCfDateGetEpoch(CFTypeRef cf, uint64_t* result);
+const char* ffCfDataGetDataAsString(CFTypeRef cf, FFstrbuf* result);
+const char* ffCfDictGetString(CFDictionaryRef dict, CFStringRef key, FFstrbuf* result);
+const char* ffCfDictGetBool(CFDictionaryRef dict, CFStringRef key, bool* result);
+const char* ffCfDictGetInt(CFDictionaryRef dict, CFStringRef key, int* result);
+const char* ffCfDictGetInt64(CFDictionaryRef dict, CFStringRef key, int64_t* result);
+const char* ffCfDictGetDouble(CFDictionaryRef dict, CFStringRef key, double* result);
+const char* ffCfDictGetData(CFDictionaryRef dict, CFStringRef key, uint32_t offset, uint32_t size, uint8_t* result, uint32_t* length);
+const char* ffCfDictGetDataAsString(CFDictionaryRef dict, CFStringRef key, FFstrbuf* result);
+const char* ffCfDictGetDict(CFDictionaryRef dict, CFStringRef key, CFDictionaryRef* result);
+const char* ffCfDictGetDateAsEpoch(CFDictionaryRef dict, CFStringRef key, uint64_t* result);
+
+static inline CFNumberRef ffCfCreateInt(int value) {
+ return CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &value);
+}
+
+static inline void cfReleaseWrapper(void* type) {
+ assert(type);
+ if (*(CFTypeRef*) type) {
+ CFRelease(*(CFTypeRef*) type);
+ }
+}
+
+#define FF_CFTYPE_AUTO_RELEASE FF_A_CLEANUP(cfReleaseWrapper)
+
+static inline void wrapIoObjectRelease(io_object_t* service) {
+ assert(service);
+ if (*service) {
+ IOObjectRelease(*service);
+ }
+}
+#define FF_IOOBJECT_AUTO_RELEASE FF_A_CLEANUP(wrapIoObjectRelease)