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. */
13 #include "go-string.h"
15 /* Set the C environment from Go. This is called by syscall.Setenv. */
17 void setenv_c (struct __go_string
, struct __go_string
)
18 __asm__ ("libgo_syscall.syscall.setenv_c");
21 setenv_c (struct __go_string k
, struct __go_string v
)
23 const unsigned char *ks
;
25 const unsigned char *vs
;
35 if (ks
[k
.__length
] != 0)
37 kn
= __go_alloc (k
.__length
+ 1);
38 __builtin_memcpy (kn
, ks
, k
.__length
);
42 if (vs
[v
.__length
] != 0)
44 vn
= __go_alloc (v
.__length
+ 1);
45 __builtin_memcpy (vn
, vs
, v
.__length
);
49 setenv ((const char *) ks
, (const char *) vs
, 1);
51 #else /* !defined(HAVE_SETENV) */
53 kn
= malloc (k
.__length
+ v
.__length
+ 2);
54 __builtin_memcpy (kn
, ks
, k
.__length
);
56 __builtin_memcpy (kn
+ k
.__length
+ 1, vs
, v
.__length
);
57 kn
[k
.__length
+ v
.__length
+ 1] = '\0';
60 #endif /* !defined(HAVE_SETENV) */