- long values_space = (env_var_count * (PATH_MAX + 64));
-
- void * buffer;
- char ** vars;
- char * values;
- int vars_index = 0;
- unsigned int chars_printed;
-
- /* Allocate buffer for environment variables: first in the buffer is an
- * array of pointers to argument strings, terminated with a NULL pointer.
- * After that the argument strings are placed after each other */
- buffer = malloc(((env_var_count + 1) * sizeof(char *)) + values_space);
- if (!buffer)
- return NULL;
-
- vars = buffer;
- values = (char *) &vars[env_var_count + 1];
-
- /* loop over all defined environment variables and their values */
- while (vars_index < env_var_count) {
- char * name = env_vars[vars_index].name;
- char * value = env_vars[vars_index].value;
-
- if (!value)
- value = "";
-
- chars_printed = snprintf(values, (values_space - 1), "%s=%s", name,
- value);
- if (chars_printed > (values_space - 1)) {
- /* Buffer space exhausted: stop adding variables.
- * Not all environment variables are defined, but the best we can
- * do is to provide the ones that _are_ defined */
- break;
- }
-
- values[chars_printed] = '\0';
- *&vars[vars_index] = values;
- values += (chars_printed + 1);
- values_space -= (chars_printed + 1);
- vars_index++;
- }
-
- /* terminate the array with pointers */
- *&vars[vars_index] = NULL;
-
- return (char *) buffer;
+ cgit_env_var *p, *q;
+ static char *warn = "cgit warning: failed to set env: %s=%s\n";
+
+ p = env_vars;
+ q = p + env_var_count;
+ for (; p < q; p++)
+ if (setenv(p->name, p->value, 1))
+ fprintf(stderr, warn, p->name, p->value);