aboutsummaryrefslogtreecommitdiff
path: root/src/bun.zig
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/bun.zig15
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];
+}