144743Smarkm /*
244743Smarkm  * Some systems do not have setenv(). This one is modeled after 4.4 BSD, but
344743Smarkm  * is implemented in terms of portable primitives only: getenv(), putenv()
444743Smarkm  * and malloc(). It should therefore be safe to use on every UNIX system.
544743Smarkm  *
644743Smarkm  * If clobber == 0, do not overwrite an existing variable.
744743Smarkm  *
844743Smarkm  * Returns nonzero if memory allocation fails.
944743Smarkm  *
1044743Smarkm  * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
1144743Smarkm  */
1244743Smarkm
1344743Smarkm#ifndef lint
1444743Smarkmstatic char sccsid[] = "@(#) setenv.c 1.1 93/03/07 22:47:58";
1544743Smarkm#endif
1644743Smarkm
1744743Smarkm/* setenv - update or insert environment (name,value) pair */
1844743Smarkm
1944743Smarkmint     setenv(name, value, clobber)
2044743Smarkmchar   *name;
2144743Smarkmchar   *value;
2244743Smarkmint     clobber;
2344743Smarkm{
2444743Smarkm    char   *malloc();
2544743Smarkm    char   *getenv();
2644743Smarkm    char   *cp;
2744743Smarkm
2844743Smarkm    if (clobber == 0 && getenv(name) != 0)
2944743Smarkm	return (0);
3044743Smarkm    if ((cp = malloc(strlen(name) + strlen(value) + 2)) == 0)
3144743Smarkm	return (1);
3244743Smarkm    sprintf(cp, "%s=%s", name, value);
3344743Smarkm    return (putenv(cp));
3444743Smarkm}
35