2022-05-28 14:42:05 +01:00
|
|
|
const std = @import("std");
|
|
|
|
const common = @import("./common.zig");
|
2022-11-30 15:20:34 +00:00
|
|
|
const builtin = @import("builtin");
|
2022-05-28 14:42:05 +01:00
|
|
|
|
|
|
|
comptime {
|
2022-11-30 15:20:34 +00:00
|
|
|
if (builtin.object_format != .c) {
|
2022-12-28 13:57:17 +00:00
|
|
|
@export(memset, .{ .name = "memset", .linkage = common.linkage, .visibility = common.visibility });
|
|
|
|
@export(__memset, .{ .name = "__memset", .linkage = common.linkage, .visibility = common.visibility });
|
2022-11-30 15:20:34 +00:00
|
|
|
}
|
2022-05-28 14:42:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn memset(dest: ?[*]u8, c: u8, len: usize) callconv(.C) ?[*]u8 {
|
|
|
|
@setRuntimeSafety(false);
|
|
|
|
|
|
|
|
if (len != 0) {
|
|
|
|
var d = dest.?;
|
|
|
|
var n = len;
|
|
|
|
while (true) {
|
|
|
|
d[0] = c;
|
|
|
|
n -= 1;
|
|
|
|
if (n == 0) break;
|
|
|
|
d += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn __memset(dest: ?[*]u8, c: u8, n: usize, dest_n: usize) callconv(.C) ?[*]u8 {
|
|
|
|
if (dest_n < n)
|
|
|
|
@panic("buffer overflow");
|
|
|
|
return memset(dest, c, n);
|
|
|
|
}
|