From eb98380e577eb3a660eaed9bd83f6f9a660cd609 Mon Sep 17 00:00:00 2001 From: codecrafters-bot Date: Fri, 5 Dec 2025 03:43:32 +0000 Subject: init [skip ci] --- src/main.zig | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 src/main.zig (limited to 'src') diff --git a/src/main.zig b/src/main.zig new file mode 100755 index 0000000..eb8124b --- /dev/null +++ b/src/main.zig @@ -0,0 +1,37 @@ +const std = @import("std"); +var stdout_buffer: [1024]u8 = undefined; +var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); +const stdout = &stdout_writer.interface; + +pub fn main() !void { + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + defer _ = gpa.deinit(); + const allocator = gpa.allocator(); + + const args = try std.process.argsAlloc(allocator); + defer std.process.argsFree(allocator, args); + + if (args.len < 3) { + std.debug.print("Usage: {s} \n", .{args[0]}); + std.process.exit(1); + } + + const database_file_path: []const u8 = args[1]; + const command: []const u8 = args[2]; + + if (std.mem.eql(u8, command, ".dbinfo")) { + var file = try std.fs.cwd().openFile(database_file_path, .{}); + defer file.close(); + + // You can use print statements as follows for debugging, they'll be visible when running tests. + std.debug.print("Logs from your program will appear here!\n", .{}); + + // TODO: Uncomment the code below to pass the first stage + // var buf: [2]u8 = undefined; + // _ = try file.seekTo(16); + // _ = try file.read(&buf); + // const page_size = std.mem.readInt(u16, &buf, .big); + // try stdout.print("database page size: {}\n", .{page_size}); + // try stdout.flush(); + } +} -- cgit v1.2.3