blob: eb8124b387635d660a32cac37bd228013e51bcfc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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();
}
}
|