2017-04-28 Hristian Kirtchev <kirtchev@adacore.com>
[official-gcc.git] / libgo / runtime / go-unsetenv.c
blob21359975f2b3e9053496482ef853ddf4192bab0b
1 /* go-unsetenv.c -- unset an environment variable from Go.
3 Copyright 2015 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. */
7 #include "config.h"
9 #include <stddef.h>
10 #include <stdlib.h>
12 #include "runtime.h"
14 /* Unset an environment variable from Go. This is called by
15 syscall.Unsetenv. */
17 void unsetenv_c (String) __asm__ (GOSYM_PREFIX "syscall.unsetenv_c");
19 void
20 unsetenv_c (String k)
22 const byte *ks;
23 unsigned char *kn;
25 ks = k.str;
26 if (ks == NULL)
27 ks = (const byte *) "";
28 kn = NULL;
30 #ifdef HAVE_UNSETENV
32 if (ks[k.len] != 0)
34 kn = malloc (k.len + 1);
35 if (kn == NULL)
36 runtime_throw ("out of malloc memory");
37 __builtin_memcpy (kn, ks, k.len);
38 ks = kn;
41 unsetenv ((const char *) ks);
43 #endif /* !defined(HAVE_UNSETENV) */
45 if (kn != NULL)
46 free (kn);