1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include "cr_environment.h"
|
---|
8 | #include "cr_string.h"
|
---|
9 | #include "cr_mem.h"
|
---|
10 | #include <stdlib.h>
|
---|
11 | #include <stdio.h>
|
---|
12 |
|
---|
13 | void crSetenv( const char *var, const char *value )
|
---|
14 | {
|
---|
15 | #if defined(LINUX) || defined(FREEBSD) || defined(DARWIN)
|
---|
16 | setenv( var, value, 1 /* replace */ );
|
---|
17 | #else
|
---|
18 | unsigned long len;
|
---|
19 | char *buf;
|
---|
20 |
|
---|
21 | len = crStrlen(var) + 1 + crStrlen(value) + 1;
|
---|
22 | buf = (char *) crAlloc( len );
|
---|
23 | sprintf( buf, "%s=%s", var, value );
|
---|
24 | putenv( buf );
|
---|
25 |
|
---|
26 | /* don't free the buf, the string is *part* of the environment,
|
---|
27 | * and can't be reclaimed */
|
---|
28 | #endif
|
---|
29 | }
|
---|
30 |
|
---|
31 | const char *crGetenv( const char *var )
|
---|
32 | {
|
---|
33 | return getenv( var );
|
---|
34 | }
|
---|