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. */
17 /* Set the C environment from Go. This is called by syscall.Setenv. */
19 void setenv_c (String
, String
) __asm__ (GOSYM_PREFIX
"syscall.setenv_c");
22 setenv_c (String k
, String v
)
32 ks
= (const byte
*) "";
37 vs
= (const byte
*) "";
42 if (ks
!= NULL
&& ks
[k
.len
] != 0)
44 // Objects that are explicitly freed must be at least 16 bytes in size,
45 // so that they are not allocated using tiny alloc.
49 kn
= __go_alloc (len
);
50 __builtin_memcpy (kn
, ks
, k
.len
);
54 if (vs
!= NULL
&& vs
[v
.len
] != 0)
59 vn
= __go_alloc (len
);
60 __builtin_memcpy (vn
, vs
, v
.len
);
64 setenv ((const char *) ks
, (const char *) vs
, 1);
66 #else /* !defined(HAVE_SETENV) */
68 len
= k
.len
+ v
.len
+ 2;
71 kn
= __go_alloc (len
);
72 __builtin_memcpy (kn
, ks
, k
.len
);
74 __builtin_memcpy (kn
+ k
.len
+ 1, vs
, v
.len
);
75 kn
[k
.len
+ v
.len
+ 1] = '\0';
78 #endif /* !defined(HAVE_SETENV) */