GRASS GIS 7 Programmer's Manual
7.0.3(2016)-r00000
Main Page
Related Pages
Data Structures
Files
File List
Globals
putenv.c
Go to the documentation of this file.
1
15
#include <string.h>
16
#include <stdio.h>
17
#include <stdlib.h>
18
#include <grass/config.h>
19
#include <grass/gis.h>
20
21
#if !defined(HAVE_PUTENV) && !defined(HAVE_SETENV)
22
extern
char
**
environ
;
23
#endif
24
31
void
G_putenv
(
const
char
*
name
,
const
char
*value)
32
{
33
char
buf[1024];
34
35
#if defined(HAVE_PUTENV)
36
sprintf(buf,
"%s=%s"
, name, value);
37
putenv(
G_store
(buf));
38
#elif defined(HAVE_SETENV)
39
setenv(name, value, 1);
40
#else
41
static
int
first = 1;
42
int
i;
43
char
**newenv;
44
char
*env;
45
46
if
(first) {
47
for
(i = 0;
environ
[i]; i++) ;
48
newenv = (
char
**)G_malloc((i + 1) *
sizeof
(
char
*));
49
for
(i = 0; env =
environ
[i], env; i++)
50
newenv[i] =
G_store
(env);
51
newenv[i] =
NULL
;
52
environ
= newenv;
53
first = 0;
54
}
55
56
for
(i = 0; env =
environ
[i], env; i++) {
57
char
temp[4];
58
59
if
(sscanf(env,
"%[^=]=%1s"
, buf, temp) < 1)
60
continue
;
61
62
if
(strcmp(buf, name) != 0)
63
continue
;
64
65
G_free
(env);
66
sprintf(buf,
"%s=%s"
, name, value);
67
environ
[i] =
G_store
(buf);
68
69
return
;
70
}
71
environ
= (
char
**)G_realloc(
environ
, (i + 2) *
sizeof
(
char
*));
72
sprintf(buf,
"%s=%s"
, name, value);
73
environ
[i++] =
G_store
(buf);
74
environ
[i] =
NULL
;
75
#endif
76
}
G_store
char * G_store(const char *s)
Copy string to allocated memory.
Definition:
strings.c:86
NULL
#define NULL
Definition:
ccmath.h:32
G_putenv
void G_putenv(const char *name, const char *value)
Sets the UNIX environment variable name to value.
Definition:
putenv.c:31
name
const char * name
Definition:
named_colr.c:7
G_free
void G_free(void *buf)
Free allocated memory.
Definition:
alloc.c:149
environ
char ** environ
gis
putenv.c
Generated on Wed Mar 2 2016 13:36:07 for GRASS GIS 7 Programmer's Manual by
1.8.11