From df06eee5e8212f137238f152bb6d37c0dae25c8d Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Mon, 29 Jul 2019 01:19:59 +1000 Subject: [PATCH] fn copy(dst, src) []byte --- vlib/builtin/array.v | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index 78591e8852..ea4278fe0c 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -251,3 +251,13 @@ pub fn (b []byte) hex() string { } return string(hex) } + +// TODO: implement for all types +pub fn copy(dst, src []byte) int { + if dst.len > 0 && src.len > 0 { + min := if dst.len < src.len { dst.len } else { src.len } + C.memcpy(dst.data, src.left(min).data, dst.element_size*min) + return min + } + return 0 +}