Added SILC Thread Queue API
[silc.git] / lib / silcutil / silcenv.c
1 /*
2
3   silcenv.c
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2007 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 "silc.h"
21
22 /* Set environment variable with value */
23
24 SilcBool silc_setenv(const char *variable, const char *value)
25 {
26   SILC_LOG_DEBUG(("Set %s=%s", variable, value));
27 #if defined(HAVE_SETENV)
28   return setenv(variable, value, TRUE) == 0;
29 #elif defined (HAVE_PUTENV)
30   char tmp[1024];
31   silc_snprintf(tmp, sizeof(tmp), "%s=%s", variable, value);
32   return putenv(tmp) == 0;
33 #endif /* HAVE_SETENV */
34   return FALSE;
35 }
36
37 /* Get environment variable value */
38
39 const char *silc_getenv(const char *variable)
40 {
41   SILC_LOG_DEBUG(("Get %s value", variable));
42 #if defined(HAVE_GETENV)
43   return (const char *)getenv(variable);
44 #endif /* HAVE_GETENV */
45   return NULL;
46 }
47
48 /* Unset environment variable */
49
50 SilcBool silc_unsetenv(const char *variable)
51 {
52   SILC_LOG_DEBUG(("Unset %s value", variable));
53 #if defined(HAVE_UNSETENV)
54   return unsetenv(variable) == 0;
55 #endif /* HAVE_GETENV */
56   return FALSE;
57 }
58
59 /* Clear environment */
60
61 SilcBool silc_clearenv(void)
62 {
63   SILC_LOG_DEBUG(("Clear allenvironment variables"));
64 #if defined(HAVE_CLEARENV)
65   return clearenv() == 0;
66 #endif /* HAVE_GETENV */
67   return FALSE;
68 }