From 092171ef7f305b8df76dc7dc03847e6eac741f9f Mon Sep 17 00:00:00 2001 From: utox39 Date: Mon, 25 Aug 2025 02:04:41 +0200 Subject: [PATCH] refactor(macos-utils): converts a CFTypeRef casted to CFStringRef to a Zig string --- src/macos/utils.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/macos/utils.zig b/src/macos/utils.zig index 8ba216a..48046af 100644 --- a/src/macos/utils.zig +++ b/src/macos/utils.zig @@ -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));