
/*
 * Copyright 1993, 1994, 1995 by the Regents of the University of California
 * see the file "Copyright" in the distribution for conditions of use.
 */

#include <stdio.h>

/*
 *	setenv() -
 *
 *	a basic setenv().
 *	included because some systems don't have a built-in setenv()
 *	not full featured - just what is needed for the menu
 */

extern char **environ;

setenv( var_name, string, override )
char *var_name;
char *string;
int override;
{
	char **env;
	char *temp;
	char **longer;
	int i;
	int n;

	temp = (char *) malloc( strlen(var_name)+2+strlen(string) );
	strcpy( temp, var_name );
	strcat( temp, "=" );
	n = strlen( temp );
	strcat( temp, string );

	env = environ;
	for( env = environ; *env != NULL; env++ ) {
		if( strncmp( *env, temp, n ) == 0 ) {
			*env = temp;
			return 1;
		}
	}

	n = env - environ + 1;
	longer = (char **) malloc( (n+2)*sizeof(char *) );
	for( i = 0; i < env - environ; i++ ) {
		longer[i] = environ[i];
	}
	longer[i++] = temp;
	longer[i] = NULL;
	environ = longer;
}
