refactor(macos-utils): converts a CFTypeRef casted to CFStringRef to a Zig string

This commit is contained in:
utox39
2025-08-25 02:04:41 +02:00
parent 84a5edba4c
commit 092171ef7f

View File

@@ -1,8 +1,10 @@
const std = @import("std");
const c_iokit = @cImport(@cInclude("IOKit/IOKitLib.h"));
/// Converts a CFString to a Zig string.
pub fn cfStringToZigString(allocator: std.mem.Allocator, cf_string: c_iokit.CFStringRef) ![]u8 {
/// Converts a CFTypeRef casted to CFStringRef to a Zig string.
pub fn cfTypeRefToZigString(allocator: std.mem.Allocator, cf_type_ref: c_iokit.CFTypeRef) ![]u8 {
const cf_string: c_iokit.CFStringRef = @ptrFromInt(@intFromPtr(cf_type_ref));
const length = c_iokit.CFStringGetLength(cf_string);
const max_size = c_iokit.CFStringGetMaximumSizeForEncoding(length, c_iokit.kCFStringEncodingUTF8) + 1;
const max_size_usize = @as(usize, @intCast(max_size));