mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
* Introduce common `bzero` libc implementation. * Update test name according to review Co-authored-by: Linus Groh <mail@linusgroh.de> * address code review - import common implementation when musl or wasi is included - don't use `c_builtins`, use `@memset` * bzero calling conv to .c * Apply review Co-authored-by: Veikka Tuominen <git@vexu.eu> --------- Co-authored-by: Linus Groh <mail@linusgroh.de> Co-authored-by: Veikka Tuominen <git@vexu.eu>
19 lines
549 B
Zig
19 lines
549 B
Zig
const std = @import("std");
|
|
const common = @import("common.zig");
|
|
|
|
comptime {
|
|
@export(&bzero, .{ .name = "bzero", .linkage = common.linkage, .visibility = common.visibility });
|
|
}
|
|
|
|
fn bzero(s: *anyopaque, n: usize) callconv(.c) void {
|
|
const s_cast: [*]u8 = @ptrCast(s);
|
|
@memset(s_cast[0..n], 0);
|
|
}
|
|
|
|
test bzero {
|
|
var array: [10]u8 = [_]u8{ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
|
|
var a = std.mem.zeroes([array.len]u8);
|
|
a[9] = '0';
|
|
bzero(&array[0], 9);
|
|
try std.testing.expect(std.mem.eql(u8, &array, &a));
|
|
}
|