Skip to content

Commit

Permalink
sliceAddNull
Browse files Browse the repository at this point in the history
  • Loading branch information
donpdonp committed Apr 9, 2024
1 parent d111420 commit 9c45b15
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/gui/gtk3.zig
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ fn g_signal_connect(instance: anytype, signal_name: []const u8, callback: anytyp
// connect_flags: GConnectFlags) gulong;
// connect_flags: GConnectFlags) gulong;
// typedef void* gpointer;
var signal_name_null: []u8 = std.cstr.addNullByte(allocator, signal_name) catch unreachable;
var signal_name_null: []const u8 = util.sliceAddNull(allocator, signal_name);
var data_ptr: ?*anyopaque = undefined;
if (@sizeOf(@TypeOf(data)) != 0) {
data_ptr = @as(?*anyopaque, @ptrCast(data));
Expand Down
2 changes: 1 addition & 1 deletion src/gui/gtk4.zig
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ fn g_signal_connect(instance: anytype, signal_name: []const u8, callback: anytyp
// connect_flags: GConnectFlags) gulong;
// connect_flags: GConnectFlags) gulong;
// typedef void* gpointer;
var signal_name_null: []u8 = std.cstr.addNullByte(allocator, signal_name) catch unreachable;
var signal_name_null: []u8 = util.sliceAddNull(allocator, signal_name) catch unreachable;
var data_ptr: ?*anyopaque = undefined;
if (@sizeOf(@TypeOf(data)) != 0) {
data_ptr = @as(?*anyopaque, @ptrCast(data));
Expand Down
2 changes: 1 addition & 1 deletion src/net.zig
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn httpget(req: *config.HttpInfo) ![]const u8 {
_ = c.curl_global_init(0);
var curl = c.curl_easy_init();
if (curl != null) {
var cstr = std.cstr.addNullByte(allocator, req.url) catch unreachable;
var cstr = util.sliceAddNull(allocator, req.url) catch unreachable;
_ = c.curl_easy_setopt(curl, c.CURLOPT_URL, cstr.ptr);

var zero: c_long = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/util.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const alloc = GPAllocator.allocator();
const Buffers = @import("./simple_buffer.zig");

pub fn sliceAddNull(allocator: Allocator, str: []const u8) []const u8 {
return std.cstr.addNullByte(allocator, str) catch unreachable;
return allocator.dupeZ(u8, str) catch unreachable;
}

pub fn sliceToCstr(allocator: Allocator, str: []const u8) [*]u8 {
Expand Down

0 comments on commit 9c45b15

Please sign in to comment.