zig/std/builtin.zig
Andrew Kelley 5f0bfcac24 fix undefined reference to memcpy in release mode
when not depending on libc, we generate memcpy and memset
implementations.
2016-01-06 06:40:25 -07:00

27 lines
731 B
Zig

// These functions are provided when not linking against libc because LLVM
// sometimes generates code that calls them.
// In the future we may put these functions in separate compile units, make them .o files,
// and then use
// ar rcs foo.a foo.o memcpy.o memset.o
// ld -o foo foo.a
// This will omit the machine code if the function is unused.
export fn memset(dest: &u8, c: u8, n: usize) -> &u8 {
var index : #typeof(n) = 0;
while (index != n) {
dest[index] = c;
index += 1;
}
return dest;
}
export fn memcpy(dest: &u8, src: &const u8, n: usize) -> &u8 {
var index : #typeof(n) = 0;
while (index != n) {
dest[index] = src[index];
index += 1;
}
return dest;
}