mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: data
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
pub const c = @import("foundation/c.zig");
|
pub const c = @import("foundation/c.zig");
|
||||||
pub usingnamespace @import("foundation/array.zig");
|
pub usingnamespace @import("foundation/array.zig");
|
||||||
pub usingnamespace @import("foundation/base.zig");
|
pub usingnamespace @import("foundation/base.zig");
|
||||||
|
pub usingnamespace @import("foundation/data.zig");
|
||||||
pub usingnamespace @import("foundation/dictionary.zig");
|
pub usingnamespace @import("foundation/dictionary.zig");
|
||||||
pub usingnamespace @import("foundation/number.zig");
|
pub usingnamespace @import("foundation/number.zig");
|
||||||
pub usingnamespace @import("foundation/string.zig");
|
pub usingnamespace @import("foundation/string.zig");
|
||||||
|
30
pkg/macos/foundation/data.zig
Normal file
30
pkg/macos/foundation/data.zig
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const Allocator = std.mem.Allocator;
|
||||||
|
const foundation = @import("../foundation.zig");
|
||||||
|
const c = @import("c.zig");
|
||||||
|
|
||||||
|
pub const Data = opaque {
|
||||||
|
pub fn createWithBytesNoCopy(data: []const u8) Allocator.Error!*Data {
|
||||||
|
return @intToPtr(
|
||||||
|
?*Data,
|
||||||
|
@ptrToInt(c.CFDataCreateWithBytesNoCopy(
|
||||||
|
null,
|
||||||
|
data.ptr,
|
||||||
|
@intCast(c_long, data.len),
|
||||||
|
c.kCFAllocatorNull,
|
||||||
|
)),
|
||||||
|
) orelse error.OutOfMemory;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn release(self: *Data) void {
|
||||||
|
foundation.CFRelease(self);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
test {
|
||||||
|
//const testing = std.testing;
|
||||||
|
|
||||||
|
var raw = "hello world";
|
||||||
|
const data = try Data.createWithBytesNoCopy(raw);
|
||||||
|
defer data.release();
|
||||||
|
}
|
Reference in New Issue
Block a user