aboutsummaryrefslogtreecommitdiff
path: root/test/standalone/run_output_paths/create_file.zig
blob: 260c36f10cea84c132a06f72266e4ecf99c772b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const std = @import("std");

pub fn main() !void {
    var args = try std.process.argsWithAllocator(std.heap.page_allocator);
    _ = args.skip();
    const dir_name = args.next().?;
    const dir = try std.fs.cwd().openDir(if (std.mem.startsWith(u8, dir_name, "--dir="))
        dir_name["--dir=".len..]
    else
        dir_name, .{});
    const file_name = args.next().?;
    const file = try dir.createFile(file_name, .{});
    var file_writer = file.writer(&.{});
    try file_writer.interface.print(
        \\{s}
        \\{s}
        \\Hello, world!
        \\
    , .{ dir_name, file_name });
}