diff options
| author | codecrafters-bot <hello@codecrafters.io> | 2025-12-05 03:43:32 +0000 |
|---|---|---|
| committer | codecrafters-bot <hello@codecrafters.io> | 2025-12-05 03:43:32 +0000 |
| commit | eb98380e577eb3a660eaed9bd83f6f9a660cd609 (patch) | |
| tree | 78626606e82168b59b3344fa42924b520fd620b1 /src | |
| download | sqlite-zig-eb98380e577eb3a660eaed9bd83f6f9a660cd609.tar.gz sqlite-zig-eb98380e577eb3a660eaed9bd83f6f9a660cd609.zip | |
init [skip ci]
Diffstat (limited to 'src')
| -rwxr-xr-x | src/main.zig | 37 |
1 files changed, 37 insertions, 0 deletions
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} <database_file_path> <command>\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(); + } +} |