2015-01-15 01:27:56 +01:00
|
|
|
/* go-unsetenv.c -- unset an environment variable from Go.
|
|
|
|
|
|
|
|
Copyright 2015 The Go Authors. All rights reserved.
|
|
|
|
Use of this source code is governed by a BSD-style
|
|
|
|
license that can be found in the LICENSE file. */
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "runtime.h"
|
|
|
|
|
|
|
|
/* Unset an environment variable from Go. This is called by
|
|
|
|
syscall.Unsetenv. */
|
|
|
|
|
2020-11-17 05:06:53 +01:00
|
|
|
void unsetenv_c (String) __asm__ (GOSYM_PREFIX "syscall.unsetenv__c");
|
2015-01-15 01:27:56 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
unsetenv_c (String k)
|
|
|
|
{
|
|
|
|
const byte *ks;
|
|
|
|
unsigned char *kn;
|
|
|
|
|
|
|
|
ks = k.str;
|
|
|
|
if (ks == NULL)
|
|
|
|
ks = (const byte *) "";
|
|
|
|
kn = NULL;
|
|
|
|
|
|
|
|
#ifdef HAVE_UNSETENV
|
|
|
|
|
2016-11-18 17:03:13 +01:00
|
|
|
if (ks[k.len] != 0)
|
2015-01-15 01:27:56 +01:00
|
|
|
{
|
2016-11-18 17:03:13 +01:00
|
|
|
kn = malloc (k.len + 1);
|
|
|
|
if (kn == NULL)
|
|
|
|
runtime_throw ("out of malloc memory");
|
2015-01-15 01:27:56 +01:00
|
|
|
__builtin_memcpy (kn, ks, k.len);
|
|
|
|
ks = kn;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsetenv ((const char *) ks);
|
|
|
|
|
|
|
|
#endif /* !defined(HAVE_UNSETENV) */
|
|
|
|
|
|
|
|
if (kn != NULL)
|
2016-11-18 17:03:13 +01:00
|
|
|
free (kn);
|
2015-01-15 01:27:56 +01:00
|
|
|
}
|