| ... | ... | @@ -14,26 +14,43 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) noreturn |
| 14 | 14 | } |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | | // Note that memset does not return `dest`, like the libc API. |
| 18 | | // The semantics of memset is dictated by the corresponding |
| 19 | | // LLVM intrinsics, not by the libc API. |
| 20 | | export fn memset(dest: ?&u8, c: u8, n: usize) void { |
| 17 | export fn memset(dest: ?&u8, c: u8, n: usize) ?&u8 { |
| 21 | 18 | @setRuntimeSafety(false); |
| 22 | 19 | |
| 23 | 20 | var index: usize = 0; |
| 24 | 21 | while (index != n) : (index += 1) |
| 25 | 22 | (??dest)[index] = c; |
| 23 | |
| 24 | return dest; |
| 26 | 25 | } |
| 27 | 26 | |
| 28 | | // Note that memcpy does not return `dest`, like the libc API. |
| 29 | | // The semantics of memcpy is dictated by the corresponding |
| 30 | | // LLVM intrinsics, not by the libc API. |
| 31 | | export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) void { |
| 27 | export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) ?&u8 { |
| 32 | 28 | @setRuntimeSafety(false); |
| 33 | 29 | |
| 34 | 30 | var index: usize = 0; |
| 35 | 31 | while (index != n) : (index += 1) |
| 36 | 32 | (??dest)[index] = (??src)[index]; |
| 33 | |
| 34 | return dest; |
| 35 | } |
| 36 | |
| 37 | export fn memmove(dest: ?&u8, src: ?&const u8, n: usize) ?&u8 { |
| 38 | @setRuntimeSafety(false); |
| 39 | |
| 40 | if (@ptrToInt(dest) < @ptrToInt(src)) { |
| 41 | var index: usize = 0; |
| 42 | while (index != n) : (index += 1) { |
| 43 | (??dest)[index] = (??src)[index]; |
| 44 | } |
| 45 | } else { |
| 46 | var index = n; |
| 47 | while (index != 0) { |
| 48 | index -= 1; |
| 49 | (??dest)[index] = (??src)[index]; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | return dest; |
| 37 | 54 | } |
| 38 | 55 | |
| 39 | 56 | comptime { |