mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
31 lines
769 B
Zig
31 lines
769 B
Zig
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();
|
|
}
|