blob: 75f9e46d16d5d52dc2b4ea128fff7e2bd3e9040c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
const std = @import("std");
const common = @import("./common.zig");
comptime {
@export(&memmove, .{ .name = "memmove", .linkage = common.linkage, .visibility = common.visibility });
}
pub fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) callconv(.C) ?[*]u8 {
@setRuntimeSafety(false);
if (@intFromPtr(dest) < @intFromPtr(src)) {
var index: usize = 0;
while (index != n) : (index += 1) {
dest.?[index] = src.?[index];
}
} else {
var index = n;
while (index != 0) {
index -= 1;
dest.?[index] = src.?[index];
}
}
return dest;
}
|