2011-10-08 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / libgo / runtime / go-byte-array-to-string.c
blobab9e28388bc3efc29f2b18be2e5eefcabb286e51
1 /* go-byte-array-to-string.c -- convert an array of bytes to a string in Go.
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. */
7 #include "go-string.h"
8 #include "runtime.h"
9 #include "malloc.h"
11 struct __go_string
12 __go_byte_array_to_string (const void* p, int len)
14 const unsigned char *bytes;
15 unsigned char *retdata;
16 struct __go_string ret;
18 bytes = (const unsigned char *) p;
19 retdata = runtime_mallocgc (len, FlagNoPointers, 1, 0);
20 __builtin_memcpy (retdata, bytes, len);
21 ret.__data = retdata;
22 ret.__length = len;
23 return ret;