diff options
| author | Motiejus Jakštys <motiejus@uber.com> | 2023-01-23 21:59:03 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-05-16 16:40:58 -0700 |
| commit | 2e692312f104e1e5533c9f389d73488ea4a1ef68 (patch) | |
| tree | 41c075be8388dc374bfd2f01973a6f8dfb612939 /lib/std/Build/Cache.zig | |
| parent | b754068fbc7492962953068d31386d4c04e37ae5 (diff) | |
| download | zig-2e692312f104e1e5533c9f389d73488ea4a1ef68.tar.gz zig-2e692312f104e1e5533c9f389d73488ea4a1ef68.zip | |
zig cc: support reading from non-files
echo 'some C program' | $CC -x c -
Is a common pattern to test for compiler or linker features. This patch
adds support for reading from non-regular files.
This will make at least one more Go test to pass.
Diffstat (limited to 'lib/std/Build/Cache.zig')
| -rw-r--r-- | lib/std/Build/Cache.zig | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/std/Build/Cache.zig b/lib/std/Build/Cache.zig index 17429c0370..4fc6784684 100644 --- a/lib/std/Build/Cache.zig +++ b/lib/std/Build/Cache.zig @@ -31,6 +31,16 @@ pub const Directory = struct { } } + pub fn tmpFilePath(self: Directory, ally: Allocator, suffix: []const u8) error{OutOfMemory}![]const u8 { + const s = std.fs.path.sep_str; + const rand_int = std.crypto.random.int(u64); + if (self.path) |p| { + return std.fmt.allocPrint(ally, "{s}" ++ s ++ "tmp" ++ s ++ "{x}-{s}", .{ p, rand_int, suffix }); + } else { + return std.fmt.allocPrint(ally, "tmp" ++ s ++ "{x}-{s}", .{ rand_int, suffix }); + } + } + /// Whether or not the handle should be closed, or the path should be freed /// is determined by usage, however this function is provided for convenience /// if it happens to be what the caller needs. |
