| author | |
| committer | |
| log | 2c241b263cf165cdde4b3b1df3ce551d915ee476 |
| tree | 881e74dc9d0408705a082cd26c2178602c52efb6 |
| parent | 85431e745cda668bb4559b2839834d4899141e2e |
| signature |
* 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>5 files changed, 20 insertions(+), 10 deletions(-)
lib/c.zig+1| ... | @@ -17,6 +17,7 @@ comptime { | ... | @@ -17,6 +17,7 @@ comptime { |
| 17 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | 17 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { |
| 18 | // Files specific to musl and wasi-libc. | 18 | // Files specific to musl and wasi-libc. |
| 19 | _ = @import("c/string.zig"); | 19 | _ = @import("c/string.zig"); |
| 20 | _ = @import("c/strings.zig"); | ||
| 20 | } | 21 | } |
| 21 | 22 | ||
| 22 | if (builtin.target.isMuslLibC()) { | 23 | if (builtin.target.isMuslLibC()) { |
lib/c/strings.zig created+19| ... | @@ -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 deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <string.h> | ||
| 3 | #include <strings.h> | ||
| 4 | |||
| 5 | void bzero(void *s, size_t n) | ||
| 6 | { | ||
| 7 | 	memset(s, 0, n); | ||
| 8 | } | ||
src/musl.zig-1| ... | @@ -1840,7 +1840,6 @@ const src_files = [_][]const u8{ | ... | @@ -1840,7 +1840,6 @@ const src_files = [_][]const u8{ |
| 1840 | "musl/src/string/arm/__aeabi_memset.s", | 1840 | "musl/src/string/arm/__aeabi_memset.s", |
| 1841 | "musl/src/string/bcmp.c", | 1841 | "musl/src/string/bcmp.c", |
| 1842 | "musl/src/string/bcopy.c", | 1842 | "musl/src/string/bcopy.c", |
| 1843 | "musl/src/string/bzero.c", | ||
| 1844 | "musl/src/string/explicit_bzero.c", | 1843 | "musl/src/string/explicit_bzero.c", |
| 1845 | "musl/src/string/i386/memset.s", | 1844 | "musl/src/string/i386/memset.s", |
| 1846 | "musl/src/string/index.c", | 1845 | "musl/src/string/index.c", |
src/wasi_libc.zig-1| ... | @@ -1044,7 +1044,6 @@ const libc_top_half_src_files = [_][]const u8{ | ... | @@ -1044,7 +1044,6 @@ const libc_top_half_src_files = [_][]const u8{ |
| 1044 | "musl/src/stdlib/qsort_nr.c", | 1044 | "musl/src/stdlib/qsort_nr.c", |
| 1045 | "musl/src/string/bcmp.c", | 1045 | "musl/src/string/bcmp.c", |
| 1046 | "musl/src/string/bcopy.c", | 1046 | "musl/src/string/bcopy.c", |
| 1047 | "musl/src/string/bzero.c", | ||
| 1048 | "musl/src/string/explicit_bzero.c", | 1047 | "musl/src/string/explicit_bzero.c", |
| 1049 | "musl/src/string/index.c", | 1048 | "musl/src/string/index.c", |
| 1050 | "musl/src/string/memccpy.c", | 1049 | "musl/src/string/memccpy.c", |