go-string-to-byte-array.c 678 Bytes
Newer Older
1 2 3 4 5 6 7
/* go-string-to-byte-array.c -- convert a string to an array of bytes in Go.

   Copyright 2010 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"
8
#include "array.h"
9
#include "arch.h"
10 11 12
#include "malloc.h"

struct __go_open_array
13
__go_string_to_byte_array (String str)
14 15 16 17
{
  unsigned char *data;
  struct __go_open_array ret;

18 19
  data = (unsigned char *) runtime_mallocgc (str.len, 0,
					     FlagNoScan | FlagNoZero);
20
  __builtin_memcpy (data, str.str, str.len);
21
  ret.__values = (void *) data;
22 23
  ret.__count = str.len;
  ret.__capacity = str.len;
24 25
  return ret;
}