ohmu
·
2026-10-15
1#pragma once
2
3#include "fastfetch.h"
4#include <CoreFoundation/CoreFoundation.h>
5#include <IOKit/IOKitLib.h>
6
7// Return error info if failed, nullptr otherwise
8const char* ffCfStrGetString(CFTypeRef cf, FFstrbuf* result);
9const char* ffCfNumGetInt(CFTypeRef cf, int32_t* result);
10const char* ffCfNumGetInt64(CFTypeRef cf, int64_t* result);
11const char* ffCfNumGetDouble(CFTypeRef cf, double* result);
12const char* ffCfDateGetEpoch(CFTypeRef cf, uint64_t* result);
13const char* ffCfDataGetDataAsString(CFTypeRef cf, FFstrbuf* result);
14const char* ffCfDictGetString(CFDictionaryRef dict, CFStringRef key, FFstrbuf* result);
15const char* ffCfDictGetBool(CFDictionaryRef dict, CFStringRef key, bool* result);
16const char* ffCfDictGetInt(CFDictionaryRef dict, CFStringRef key, int* result);
17const char* ffCfDictGetInt64(CFDictionaryRef dict, CFStringRef key, int64_t* result);
18const char* ffCfDictGetDouble(CFDictionaryRef dict, CFStringRef key, double* result);
19const char* ffCfDictGetData(CFDictionaryRef dict, CFStringRef key, uint32_t offset, uint32_t size, uint8_t* result, uint32_t* length);
20const char* ffCfDictGetDataAsString(CFDictionaryRef dict, CFStringRef key, FFstrbuf* result);
21const char* ffCfDictGetDict(CFDictionaryRef dict, CFStringRef key, CFDictionaryRef* result);
22const char* ffCfDictGetDateAsEpoch(CFDictionaryRef dict, CFStringRef key, uint64_t* result);
23
24static inline CFNumberRef ffCfCreateInt(int value) {
25 return CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &value);
26}
27
28static inline void cfReleaseWrapper(void* type) {
29 assert(type);
30 if (*(CFTypeRef*) type) {
31 CFRelease(*(CFTypeRef*) type);
32 }
33}
34
35#define FF_CFTYPE_AUTO_RELEASE [[gnu::cleanup(cfReleaseWrapper)]]
36
37static inline void wrapIoObjectRelease(io_object_t* service) {
38 assert(service);
39 if (*service) {
40 IOObjectRelease(*service);
41 }
42}
43#define FF_IOOBJECT_AUTO_RELEASE [[gnu::cleanup(wrapIoObjectRelease)]]