xref: /csrg-svn/lib/libc/stdlib/putenv.c (revision 42186)
142137Sbostic /*-
236771Sbostic  * Copyright (c) 1988 The Regents of the University of California.
336771Sbostic  * All rights reserved.
436771Sbostic  *
542137Sbostic  * %sccs.include.redist.c%
636771Sbostic  */
736771Sbostic 
836771Sbostic #if defined(LIBC_SCCS) && !defined(lint)
9*42186Sbostic static char sccsid[] = "@(#)putenv.c	5.3 (Berkeley) 05/17/90";
1036771Sbostic #endif /* LIBC_SCCS and not lint */
1136771Sbostic 
1242137Sbostic #include <stdlib.h>
13*42186Sbostic #include <string.h>
1442137Sbostic 
15*42186Sbostic int
1636771Sbostic putenv(str)
1736771Sbostic 	char *str;
1836771Sbostic {
19*42186Sbostic 	register char *p, *equal;
2036771Sbostic 	int rval;
2136771Sbostic 
22*42186Sbostic 	if (!(p = strdup(str)))
2336771Sbostic 		return(1);
24*42186Sbostic 	if (!(equal = index(p, '='))) {
25*42186Sbostic 		(void)free(p);
26*42186Sbostic 		return(1);
27*42186Sbostic 	}
2836771Sbostic 	*equal = '\0';
29*42186Sbostic 	rval = setenv(p, equal + 1, 1);
30*42186Sbostic 	(void)free(p);
3136771Sbostic 	return(rval);
3236771Sbostic }
33