Added memory corruption checks to stacktrace.c
[runtime.git] / lib / silcutil / silcenv.c
1 /*
2
3   silcenv.c
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2007 - 2008 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 #include "silcruntime.h"
21
22 /* Set environment variable with value */
23
24 SilcBool silc_setenv(const char *variable, const char *value)
25 {
26 #if defined(HAVE_SETENV)
27   return setenv(variable, value, TRUE) == 0;
28 #elif defined (HAVE_PUTENV)
29   char tmp[1024];
30   silc_snprintf(tmp, sizeof(tmp), "%s=%s", variable, value);
31   return putenv(tmp) == 0;
32 #endif /* HAVE_SETENV */
33   return FALSE;
34 }
35
36 /* Get environment variable value */
37
38 const char *silc_getenv(const char *variable)
39 {
40 #if defined(HAVE_GETENV)
41   return (const char *)getenv(variable);
42 #endif /* HAVE_GETENV */
43   return NULL;
44 }
45
46 /* Unset environment variable */
47
48 SilcBool silc_unsetenv(const char *variable)
49 {
50 #if defined(HAVE_UNSETENV)
51   return unsetenv(variable) == 0;
52 #endif /* HAVE_GETENV */
53   return FALSE;
54 }
55
56 /* Clear environment */
57
58 SilcBool silc_clearenv(void)
59 {
60 #if defined(HAVE_CLEARENV)
61   return clearenv() == 0;
62 #endif /* HAVE_GETENV */
63   return FALSE;
64 }