diff options
Diffstat (limited to 'std')
| -rw-r--r-- | std/bootstrap.zig | 11 | ||||
| -rw-r--r-- | std/index.zig | 17 | ||||
| -rw-r--r-- | std/io.zig | 7 | ||||
| -rw-r--r-- | std/os.zig | 8 | ||||
| -rw-r--r-- | std/str.zig | 34 |
5 files changed, 45 insertions, 32 deletions
diff --git a/std/bootstrap.zig b/std/bootstrap.zig index 849567e3cf..f381311b00 100644 --- a/std/bootstrap.zig +++ b/std/bootstrap.zig @@ -2,6 +2,7 @@ const root = @import("@root"); const linux = @import("linux.zig"); +const str = @import("str.zig"); const want_start_symbol = switch(@compile_var("os")) { linux => true, @@ -29,19 +30,11 @@ export fn _start() -> unreachable { call_main_and_exit() } -fn strlen(ptr: &const u8) -> isize { - var count: isize = 0; - while (ptr[count] != 0) { - count += 1; - } - return count; -} - fn call_main() -> %void { var args: [argc][]u8 = undefined; for (args) |arg, i| { const ptr = argv[i]; - args[i] = ptr[0...strlen(ptr)]; + args[i] = ptr[0...str.len(ptr)]; } return root.main(args); } diff --git a/std/index.zig b/std/index.zig index a7bcfc4461..e5a77be1fa 100644 --- a/std/index.zig +++ b/std/index.zig @@ -2,24 +2,9 @@ pub const Rand = @import("rand.zig").Rand; pub const io = @import("io.zig"); pub const os = @import("os.zig"); pub const math = @import("math.zig"); +pub const str = @import("str.zig"); pub fn assert(b: bool) { if (!b) unreachable{} } -pub const str_eql = slice_eql(u8); - -pub fn slice_eql(T: type)(a: []const T, b: []const T) -> bool { - if (a.len != b.len) return false; - for (a) |item, index| { - if (b[index] != item) return false; - } - return true; -} - -#attribute("test") -fn string_equality() { - assert(str_eql("abcd", "abcd")); - assert(!str_eql("abcdef", "abZdef")); - assert(!str_eql("abcdefg", "abcdef")); -} diff --git a/std/io.zig b/std/io.zig index f579db6cd9..07a480f096 100644 --- a/std/io.zig +++ b/std/io.zig @@ -207,13 +207,6 @@ pub struct InStream { } } -#attribute("cold") -pub fn abort() -> unreachable { - linux.raise(linux.SIGABRT); - linux.raise(linux.SIGKILL); - while (true) {} -} - pub error InvalidChar; pub error Overflow; diff --git a/std/os.zig b/std/os.zig index 5e0ee4878a..8771e48bba 100644 --- a/std/os.zig +++ b/std/os.zig @@ -26,3 +26,11 @@ pub fn get_random_bytes(buf: []u8) -> %void { else => unreachable{}, } } + +#attribute("cold") +pub fn abort() -> unreachable { + linux.raise(linux.SIGABRT); + linux.raise(linux.SIGKILL); + while (true) {} +} + diff --git a/std/str.zig b/std/str.zig new file mode 100644 index 0000000000..7df0c5658a --- /dev/null +++ b/std/str.zig @@ -0,0 +1,34 @@ +const assert = @import("index.zig").assert; + +pub fn len(ptr: &const u8) -> isize { + var count: isize = 0; + while (ptr[count] != 0) { + count += 1; + } + return count; +} + +pub fn from_c_const(str: &const u8) -> []const u8 { + return str[0...len(str)]; +} + +pub fn from_c(str: &u8) -> []u8 { + return str[0...len(str)]; +} + +pub const eql = slice_eql(u8); + +pub fn slice_eql(T: type)(a: []const T, b: []const T) -> bool { + if (a.len != b.len) return false; + for (a) |item, index| { + if (b[index] != item) return false; + } + return true; +} + +#attribute("test") +fn string_equality() { + assert(eql("abcd", "abcd")); + assert(!eql("abcdef", "abZdef")); + assert(!eql("abcdefg", "abcdef")); +} |
