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. */
14 /* Set the C environment from Go. This is called by syscall.Setenv. */
16 void setenv_c (String
, String
) __asm__ (GOSYM_PREFIX
"syscall.setenv_c");
19 setenv_c (String k
, String v
)
28 ks
= (const byte
*) "";
33 vs
= (const byte
*) "";
40 kn
= malloc (k
.len
+ 1);
42 runtime_throw ("out of malloc memory");
43 __builtin_memcpy (kn
, ks
, k
.len
);
50 vn
= malloc (v
.len
+ 1);
52 runtime_throw ("out of malloc memory");
53 __builtin_memcpy (vn
, vs
, v
.len
);
58 setenv ((const char *) ks
, (const char *) vs
, 1);
60 #else /* !defined(HAVE_SETENV) */
62 len
= k
.len
+ v
.len
+ 2;
65 runtime_throw ("out of malloc memory");
66 __builtin_memcpy (kn
, ks
, k
.len
);
68 __builtin_memcpy (kn
+ k
.len
+ 1, vs
, v
.len
);
69 kn
[k
.len
+ v
.len
+ 1] = '\0';
71 kn
= NULL
; /* putenv takes ownership of the string. */
73 #endif /* !defined(HAVE_SETENV) */