From 76424950e373d3b04ac3dd13019151bfba3e8423 Mon Sep 17 00:00:00 2001 From: sumuel Date: Mon, 17 Aug 2026 20:44:55 +0000 Subject: Add the files --- src/common/apple/cf_helpers.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/common/apple/cf_helpers.h (limited to 'src/common/apple/cf_helpers.h') 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 +#include + +// 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) -- cgit v1.2.3