OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [runtime/] [go-setenv.c] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
/* go-setenv.c -- set the C environment from Go.
2
 
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.  */
6
 
7
#include "config.h"
8
 
9
#include <stddef.h>
10
#include <stdlib.h>
11
 
12
#include "go-alloc.h"
13
#include "go-string.h"
14
 
15
/* Set the C environment from Go.  This is called by syscall.Setenv.  */
16
 
17
void setenv_c (struct __go_string, struct __go_string)
18
  __asm__ ("libgo_syscall.syscall.setenv_c");
19
 
20
void
21
setenv_c (struct __go_string k, struct __go_string v)
22
{
23
  const unsigned char *ks;
24
  unsigned char *kn;
25
  const unsigned char *vs;
26
  unsigned char *vn;
27
 
28
  ks = k.__data;
29
  kn = NULL;
30
  vs = v.__data;
31
  vn = NULL;
32
 
33
#ifdef HAVE_SETENV
34
 
35
  if (ks[k.__length] != 0)
36
    {
37
      kn = __go_alloc (k.__length + 1);
38
      __builtin_memcpy (kn, ks, k.__length);
39
      ks = kn;
40
    }
41
 
42
  if (vs[v.__length] != 0)
43
    {
44
      vn = __go_alloc (v.__length + 1);
45
      __builtin_memcpy (vn, vs, v.__length);
46
      vs = vn;
47
    }
48
 
49
  setenv ((const char *) ks, (const char *) vs, 1);
50
 
51
#else /* !defined(HAVE_SETENV) */
52
 
53
  kn = malloc (k.__length + v.__length + 2);
54
  __builtin_memcpy (kn, ks, k.__length);
55
  kn[k.__length] = '=';
56
  __builtin_memcpy (kn + k.__length + 1, vs, v.__length);
57
  kn[k.__length + v.__length + 1] = '\0';
58
  putenv ((char *) kn);
59
 
60
#endif /* !defined(HAVE_SETENV) */
61
 
62
  if (kn != NULL)
63
    __go_free (kn);
64
  if (vn != NULL)
65
    __go_free (vn);
66
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.