1 /* go-byte-array-to-string.c -- convert an array of bytes to a string in Go. 2 3 Copyright 2009 The Go Authors. All rights reserved. 4 Use of this source code is governed by a BSD-style 5 license that can be found in the LICENSE file. */ 6 7 #include "runtime.h" 8 #include "arch.h" 9 #include "malloc.h" 10 11 String __go_byte_array_to_string(const void * p,intgo len)12__go_byte_array_to_string (const void* p, intgo len) 13 { 14 const unsigned char *bytes; 15 unsigned char *retdata; 16 String ret; 17 18 bytes = (const unsigned char *) p; 19 retdata = runtime_mallocgc ((uintptr) len, 0, FlagNoScan); 20 __builtin_memcpy (retdata, bytes, len); 21 ret.str = retdata; 22 ret.len = len; 23 return ret; 24 } 25