zig/test/standalone/dirname/exists_in.zig
Andrew Kelley 0403f9647b std: different mechanism for disabling network dependency
On Windows, it is sometimes problematic to depend on ws2_32.dll. Before,
users of std.Io.Threaded would have to call ioBasic() rather than io()
in order to avoid unnecessary dependencies on ws2_32.dll. Now, the
application can disable networking with std.Options.

This change is necessary due to moving networking functionality to
be based on Io.Operation, which is a tagged union.
2026-03-05 22:36:33 -08:00

35 lines
894 B
Zig

//! Verifies that a file exists in a directory.
//!
//! Usage:
//!
//! ```
//! exists_in <dir> <path>
//! ```
//!
//! Where `<dir>/<path>` is the full path to the file.
//! `<dir>` must be an absolute path.
const std = @import("std");
pub fn main(init: std.process.Init) !void {
var args = try init.minimal.args.iterateAllocator(init.gpa);
defer args.deinit();
_ = args.next() orelse unreachable; // skip binary name
const dir_path = args.next() orelse {
std.log.err("missing <dir> argument", .{});
return error.BadUsage;
};
const relpath = args.next() orelse {
std.log.err("missing <path> argument", .{});
return error.BadUsage;
};
const io = std.Io.Threaded.global_single_threaded.io();
var dir = try std.Io.Dir.cwd().openDir(io, dir_path, .{});
defer dir.close(io);
_ = try dir.statFile(io, relpath, .{});
}