Skip to content

Commit 2c241b2

Browse files
kada49linusgVexu
authored
Introduce common bzero libc implementation. (#23812)
* Introduce common `bzero` libc implementation. * Update test name according to review Co-authored-by: Linus Groh <[email protected]> * 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 <[email protected]> --------- Co-authored-by: Linus Groh <[email protected]> Co-authored-by: Veikka Tuominen <[email protected]>
1 parent 85431e7 commit 2c241b2

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

lib/c.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ comptime {
1717
if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
1818
// Files specific to musl and wasi-libc.
1919
_ = @import("c/string.zig");
20+
_ = @import("c/strings.zig");
2021
}
2122

2223
if (builtin.target.isMuslLibC()) {

lib/c/strings.zig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

lib/libc/musl/src/string/bzero.c

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/musl.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,6 @@ const src_files = [_][]const u8{
18401840
"musl/src/string/arm/__aeabi_memset.s",
18411841
"musl/src/string/bcmp.c",
18421842
"musl/src/string/bcopy.c",
1843-
"musl/src/string/bzero.c",
18441843
"musl/src/string/explicit_bzero.c",
18451844
"musl/src/string/i386/memset.s",
18461845
"musl/src/string/index.c",

src/wasi_libc.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,6 @@ const libc_top_half_src_files = [_][]const u8{
10441044
"musl/src/stdlib/qsort_nr.c",
10451045
"musl/src/string/bcmp.c",
10461046
"musl/src/string/bcopy.c",
1047-
"musl/src/string/bzero.c",
10481047
"musl/src/string/explicit_bzero.c",
10491048
"musl/src/string/index.c",
10501049
"musl/src/string/memccpy.c",

0 commit comments

Comments
 (0)