diff options
author | 2023-01-27 15:26:01 -0800 | |
---|---|---|
committer | 2023-01-27 15:27:04 -0800 | |
commit | 2e1c7f5597e516133feaa5af2dc25c4794d8e113 (patch) | |
tree | c251cf73554d667475786bd7d2f66683a84d9eb1 /src/bun.zig | |
parent | 6cccc0d26c2d8acbb4c9445d3344f48c5339c6da (diff) | |
download | bun-2e1c7f5597e516133feaa5af2dc25c4794d8e113.tar.gz bun-2e1c7f5597e516133feaa5af2dc25c4794d8e113.tar.zst bun-2e1c7f5597e516133feaa5af2dc25c4794d8e113.zip |
sentinel
Diffstat (limited to '')
-rw-r--r-- | src/bun.zig | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/bun.zig b/src/bun.zig index cf3ea67a5..d555b23d1 100644 --- a/src/bun.zig +++ b/src/bun.zig @@ -933,3 +933,18 @@ pub fn sliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) SliceTo(@Typ return ptr[0..length]; } } + +pub fn cstring(input: []const u8) [:0]const u8 { + if (input.len == 0) + return ""; + + if (comptime Environment.allow_assert) { + std.debug.assert( + lenSliceTo( + @ptrCast([*:0]const u8, input.ptr), + 0, + ) == input.len, + ); + } + return @ptrCast([*:0]const u8, input.ptr)[0..input.len :0]; +} |