zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

strings.zig (549B) - Raw


      1 const std = @import("std");
      2 const common = @import("common.zig");
      3 
      4 comptime {
      5     @export(&bzero, .{ .name = "bzero", .linkage = common.linkage, .visibility = common.visibility });
      6 }
      7 
      8 fn bzero(s: *anyopaque, n: usize) callconv(.c) void {
      9     const s_cast: [*]u8 = @ptrCast(s);
     10     @memset(s_cast[0..n], 0);
     11 }
     12 
     13 test bzero {
     14     var array: [10]u8 = [_]u8{ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
     15     var a = std.mem.zeroes([array.len]u8);
     16     a[9] = '0';
     17     bzero(&array[0], 9);
     18     try std.testing.expect(std.mem.eql(u8, &array, &a));
     19 }