2 suPHP - (c)2002-2004 Sebastian Marsching <sebastian@marsching.com>
4 This file is part of suPHP.
6 suPHP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 suPHP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with suPHP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 int suphp_setenv(const char *name, const char *value, int overwrite)
31 if (!overwrite && getenv(name) != NULL)
34 putstr = malloc(strlen(name) + strlen(value) + 2);
36 error_sysmsg_exit(ERRCODE_MEMORY, "Could not allocate memory", __FILE__, __LINE__);
38 temp = putstr + strlen(name);
42 retval = putenv(putstr);
46 int suphp_unsetenv(const char *name)
48 char *putstr = malloc(strlen(name) + 2);
52 error_sysmsg_exit(ERRCODE_MEMORY, "Could not allocate memory", __FILE__, __LINE__);
54 temp = putstr + strlen(name);
58 retval = putenv(putstr);
62 char** suphp_copyenv(const char **old_env)
64 char** new_env = NULL;
65 char** element = NULL;
66 char** new_element = NULL;
67 char* firsteqchr = NULL;
70 element = (char **) old_env;
71 while (*element != NULL)
73 firsteqchr = strchr(*element, '=');
74 if (*(firsteqchr + 1) != 0)
81 new_env = (char**) malloc(sizeof(char*) * (num_elements + 1));
84 error_sysmsg_exit(ERRCODE_MEMORY, "Could not allocate memory", __FILE__, __LINE__);
86 new_element = new_env;
87 element = (char **) old_env;
88 while (*element != NULL)
90 firsteqchr = strchr(*element, '=');
91 if (*(firsteqchr + 1) != 0)
93 *new_element = malloc(strlen(*element) + 1);
94 if (*new_element == NULL)
96 error_sysmsg_exit(ERRCODE_MEMORY, "Could not allocate memory", __FILE__, __LINE__);
98 strcpy(*new_element, *element);