| ... | @@ -1,31 +1,31 @@ | ... | @@ -1,31 +1,31 @@ |
| 1 | // These functions are provided when not linking against libc because LLVM | 1 | // These functions are provided when not linking against libc because LLVM |
| 2 | // sometimes generates code that calls them. | 2 | // sometimes generates code that calls them. |
| 3 | | 3 | |
| 4 | export fn memset(dest: ?&u8, c: u8, n: usize) -> ?&u8 { | 4 | // Note that these functions do not return `dest`, like the libc API. |
| | 5 | // The semantics of these functions is dictated by the corresponding |
| | 6 | // LLVM intrinsics, not by the libc API. |
| | 7 | |
| | 8 | export fn memset(dest: ?&u8, c: u8, n: usize) { |
| 5 | @setDebugSafety(this, false); | 9 | @setDebugSafety(this, false); |
| 6 | | 10 | |
| 7 | if (n == 0) | 11 | if (n == 0) |
| 8 | return dest; | 12 | return; |
| 9 | | 13 | |
| 10 | const d = ??dest; | 14 | const d = ??dest; |
| 11 | var index: usize = 0; | 15 | var index: usize = 0; |
| 12 | while (index != n; index += 1) | 16 | while (index != n; index += 1) |
| 13 | d[index] = c; | 17 | d[index] = c; |
| 14 | | | |
| 15 | return dest; | | |
| 16 | } | 18 | } |
| 17 | | 19 | |
| 18 | export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) -> ?&u8 { | 20 | export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) { |
| 19 | @setDebugSafety(this, false); | 21 | @setDebugSafety(this, false); |
| 20 | | 22 | |
| 21 | if (n == 0) | 23 | if (n == 0) |
| 22 | return dest; | 24 | return; |
| 23 | | 25 | |
| 24 | const d = ??dest; | 26 | const d = ??dest; |
| 25 | const s = ??src; | 27 | const s = ??src; |
| 26 | var index: usize = 0; | 28 | var index: usize = 0; |
| 27 | while (index != n; index += 1) | 29 | while (index != n; index += 1) |
| 28 | d[index] = s[index]; | 30 | d[index] = s[index]; |
| 29 | | | |
| 30 | return dest; | | |
| 31 | } | 31 | } |