Retro68/gcc/libgo/runtime/go-byte-array-to-string.c

25 lines
629 B
C
Raw Normal View History

2012-03-27 23:13:14 +00:00
/* go-byte-array-to-string.c -- convert an array of bytes to a string in Go.
Copyright 2009 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file. */
#include "runtime.h"
#include "arch.h"
#include "malloc.h"
2014-09-21 17:33:12 +00:00
String
__go_byte_array_to_string (const void* p, intgo len)
2012-03-27 23:13:14 +00:00
{
const unsigned char *bytes;
unsigned char *retdata;
2014-09-21 17:33:12 +00:00
String ret;
2012-03-27 23:13:14 +00:00
bytes = (const unsigned char *) p;
2014-09-21 17:33:12 +00:00
retdata = runtime_mallocgc ((uintptr) len, 0, FlagNoScan);
2012-03-27 23:13:14 +00:00
__builtin_memcpy (retdata, bytes, len);
2014-09-21 17:33:12 +00:00
ret.str = retdata;
ret.len = len;
2012-03-27 23:13:14 +00:00
return ret;
}