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(memcpy, .{ .name = "memcpy", .linkage = common.linkage, .visibility = common.visibility });
|
2022-11-30 15:20:34 +00:00
|
|
|
}
|
2022-05-28 14:42:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, len: usize) callconv(.C) ?[*]u8 {
|
|
|
|
@setRuntimeSafety(false);
|
|
|
|
|
|
|
|
if (len != 0) {
|
|
|
|
var d = dest.?;
|
|
|
|
var s = src.?;
|
|
|
|
var n = len;
|
|
|
|
while (true) {
|
|
|
|
d[0] = s[0];
|
|
|
|
n -= 1;
|
|
|
|
if (n == 0) break;
|
|
|
|
d += 1;
|
|
|
|
s += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|