mirror of
https://github.com/ziglang/zig.git
synced 2025-12-28 09:03:21 +00:00
parent
27e881c2d7
commit
f6c77746d6
@ -14,26 +14,43 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) noreturn
|
||||
}
|
||||
}
|
||||
|
||||
// Note that memset does not return `dest`, like the libc API.
|
||||
// The semantics of memset is dictated by the corresponding
|
||||
// LLVM intrinsics, not by the libc API.
|
||||
export fn memset(dest: ?&u8, c: u8, n: usize) void {
|
||||
export fn memset(dest: ?&u8, c: u8, n: usize) ?&u8 {
|
||||
@setRuntimeSafety(false);
|
||||
|
||||
var index: usize = 0;
|
||||
while (index != n) : (index += 1)
|
||||
(??dest)[index] = c;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
// Note that memcpy does not return `dest`, like the libc API.
|
||||
// The semantics of memcpy is dictated by the corresponding
|
||||
// LLVM intrinsics, not by the libc API.
|
||||
export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) void {
|
||||
export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) ?&u8 {
|
||||
@setRuntimeSafety(false);
|
||||
|
||||
var index: usize = 0;
|
||||
while (index != n) : (index += 1)
|
||||
(??dest)[index] = (??src)[index];
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
export fn memmove(dest: ?&u8, src: ?&const u8, n: usize) ?&u8 {
|
||||
@setRuntimeSafety(false);
|
||||
|
||||
if (@ptrToInt(dest) < @ptrToInt(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;
|
||||
}
|
||||
|
||||
comptime {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user