GRASS Programmer's Manual
6.4.4(2014)-r
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Macros
Pages
putenv.c
Go to the documentation of this file.
1
#include <string.h>
2
#include <stdio.h>
3
#include <stdlib.h>
4
#include <grass/config.h>
5
#include <grass/gis.h>
6
7
/*******************************************************************
8
* G_putenv (name, value)
9
* const char *name, *value
10
*
11
* this routine sets the UNIX environment variable name to value
12
******************************************************************/
13
14
#if !defined(HAVE_PUTENV) && !defined(HAVE_SETENV)
15
extern
char
**
environ
;
16
#endif
17
18
void
G_putenv
(
const
char
*
name
,
const
char
*
value
)
19
{
20
char
buf[1024];
21
22
#if defined(HAVE_PUTENV)
23
sprintf(buf,
"%s=%s"
, name, value);
24
putenv(
G_store
(buf));
25
#elif defined(HAVE_SETENV)
26
setenv(name, value, 1);
27
#else
28
static
int
first
= 1;
29
int
i;
30
char
**newenv;
31
char
*
env
;
32
33
if
(first) {
34
for
(i = 0;
environ
[i]; i++) ;
35
newenv = (
char
**)G_malloc((i + 1) *
sizeof
(
char
*));
36
for
(i = 0; env =
environ
[i],
env
; i++)
37
newenv[i] =
G_store
(env);
38
newenv[i] =
NULL
;
39
environ
= newenv;
40
first = 0;
41
}
42
43
for
(i = 0; env =
environ
[i],
env
; i++) {
44
char
temp[4];
45
46
if
(sscanf(env,
"%[^=]=%1s"
, buf, temp) < 1)
47
continue
;
48
49
if
(strcmp(buf, name) != 0)
50
continue
;
51
52
G_free
(env);
53
sprintf(buf,
"%s=%s"
, name, value);
54
environ
[i] =
G_store
(buf);
55
56
return
;
57
}
58
environ
= (
char
**)G_realloc(
environ
, (i + 2) *
sizeof
(
char
*));
59
sprintf(buf,
"%s=%s"
, name, value);
60
environ
[i++] =
G_store
(buf);
61
environ
[i] =
NULL
;
62
#endif
63
}
G_free
void G_free(void *buf)
Free allocated memory.
Definition:
gis/alloc.c:142
NULL
#define NULL
Definition:
strings.c:26
G_store
char * G_store(const char *s)
Copy string to allocated memory.
Definition:
store.c:32
render.name
string name
Definition:
render.py:1304
main.env
tuple env
Definition:
mapdisp/main.py:134
G_putenv
void G_putenv(const char *name, const char *value)
Definition:
putenv.c:18
value
char * value
Definition:
env.c:30
first
int first
Definition:
form/open.c:25
environ
char ** environ
lib
gis
putenv.c
Generated on Fri Sep 5 2014 08:29:36 for GRASS Programmer's Manual by
1.8.8