From 350625683c066a4790f41cb91c8c05ac4fb5dd4f Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Fri, 5 Dec 2025 02:55:56 -0300 Subject: codecrafters submit [skip ci] --- src/builtins.zig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/builtins.zig') diff --git a/src/builtins.zig b/src/builtins.zig index c989a35..ea34f19 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1,7 +1,7 @@ const std = @import("std"); const path = @import("path.zig"); -const BUILTINS = [_][]const u8{ "exit", "echo", "type" }; +const BUILTINS = [_][]const u8{ "exit", "echo", "type", "pwd" }; pub const CommandResult = enum { continue_loop, @@ -27,6 +27,12 @@ pub fn executeEcho(stdout: anytype, args: ?[]const u8) !void { } } +pub fn executePwd(allocator: std.mem.Allocator, stdout: anytype) !void { + const cwd = try std.fs.cwd().realpathAlloc(allocator, "."); + defer allocator.free(cwd); + try stdout.print("{s}\n", .{cwd}); +} + pub fn executeType(allocator: std.mem.Allocator, stdout: anytype, args: ?[]const u8) !void { if (args) |a| { if (isBuiltin(a)) { -- cgit v1.2.3