command: make args type 0-terminated

Since we often need to pass these args back C code, keeping the 0 byte
around saves some allocations.
This commit is contained in:
Isaac Freund
2021-07-15 00:13:16 +02:00
parent 3c951fed74
commit 604cf98047
26 changed files with 67 additions and 77 deletions
+3 -3
View File
@@ -25,7 +25,7 @@ const util = @import("util.zig");
keysym: xkb.Keysym,
modifiers: wlr.Keyboard.ModifierMask,
command_args: []const []const u8,
command_args: []const [:0]const u8,
/// When set to true the mapping will be executed on key release rather than on press
release: bool,
@@ -36,11 +36,11 @@ pub fn init(
release: bool,
command_args: []const []const u8,
) !Self {
const owned_args = try util.gpa.alloc([]u8, command_args.len);
const owned_args = try util.gpa.alloc([:0]u8, command_args.len);
errdefer util.gpa.free(owned_args);
for (command_args) |arg, i| {
errdefer for (owned_args[0..i]) |a| util.gpa.free(a);
owned_args[i] = try std.mem.dupe(util.gpa, u8, arg);
owned_args[i] = try std.mem.dupeZ(util.gpa, u8, arg);
}
return Self{
.keysym = keysym,