Function allocPrintCmd2 [src]

Prototype

pub fn allocPrintCmd2( arena: Allocator, opt_cwd: ?[]const u8, opt_env: ?*const std.process.EnvMap, argv: []const []const u8, ) Allocator.Error![]u8

Parameters

arena: Allocatoropt_cwd: ?[]const u8opt_env: ?*const std.process.EnvMapargv: []const []const u8

Source

pub fn allocPrintCmd2( arena: Allocator, opt_cwd: ?[]const u8, opt_env: ?*const std.process.EnvMap, argv: []const []const u8, ) Allocator.Error![]u8 { var buf: std.ArrayListUnmanaged(u8) = .empty; if (opt_cwd) |cwd| try buf.writer(arena).print("cd {s} && ", .{cwd}); if (opt_env) |env| { const process_env_map = std.process.getEnvMap(arena) catch std.process.EnvMap.init(arena); var it = env.iterator(); while (it.next()) |entry| { const key = entry.key_ptr.*; const value = entry.value_ptr.*; if (process_env_map.get(key)) |process_value| { if (std.mem.eql(u8, value, process_value)) continue; } try buf.writer(arena).print("{s}={s} ", .{ key, value }); } } for (argv) |arg| { try buf.writer(arena).print("{s} ", .{arg}); } return buf.toOwnedSlice(arena); }