xref: /csrg-svn/lib/libc/stdlib/putenv.c (revision 66456)
142137Sbostic /*-
261180Sbostic  * Copyright (c) 1988, 1993
361180Sbostic  *	The Regents of the University of California.  All rights reserved.
436771Sbostic  *
542137Sbostic  * %sccs.include.redist.c%
636771Sbostic  */
736771Sbostic 
836771Sbostic #if defined(LIBC_SCCS) && !defined(lint)
9*66456Sbostic static char sccsid[] = "@(#)putenv.c	8.2 (Berkeley) 03/27/94";
1036771Sbostic #endif /* LIBC_SCCS and not lint */
1136771Sbostic 
1242137Sbostic #include <stdlib.h>
1342186Sbostic #include <string.h>
1442137Sbostic 
1542186Sbostic int
putenv(str)1636771Sbostic putenv(str)
1746599Sdonn 	const char *str;
1836771Sbostic {
19*66456Sbostic 	char *p, *equal;
2036771Sbostic 	int rval;
2136771Sbostic 
22*66456Sbostic 	if ((p = strdup(str)) == NULL)
23*66456Sbostic 		return (-1);
24*66456Sbostic 	if ((equal = index(p, '=')) == NULL) {
2542186Sbostic 		(void)free(p);
26*66456Sbostic 		return (-1);
2742186Sbostic 	}
2836771Sbostic 	*equal = '\0';
2942186Sbostic 	rval = setenv(p, equal + 1, 1);
3042186Sbostic 	(void)free(p);
31*66456Sbostic 	return (rval);
3236771Sbostic }
33