1 /* go-setenv.c -- set the C environment from Go.
3 Copyright 2011 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. */
15 /* Set the C environment from Go. This is called by syscall.Setenv. */
17 void setenv_c (String, String) __asm__ (GOSYM_PREFIX "syscall.setenv_c");
20 setenv_c (String k, String v)
29 ks = (const byte *) "";
34 vs = (const byte *) "";
39 if (ks != NULL && ks[k.len] != 0)
41 kn = __go_alloc (k.len + 1);
42 __builtin_memcpy (kn, ks, k.len);
46 if (vs != NULL && vs[v.len] != 0)
48 vn = __go_alloc (v.len + 1);
49 __builtin_memcpy (vn, vs, v.len);
53 setenv ((const char *) ks, (const char *) vs, 1);
55 #else /* !defined(HAVE_SETENV) */
57 kn = __go_alloc (k.len + v.len + 2);
58 __builtin_memcpy (kn, ks, k.len);
60 __builtin_memcpy (kn + k.len + 1, vs, v.len);
61 kn[k.len + v.len + 1] = '\0';
64 #endif /* !defined(HAVE_SETENV) */