xref: /csrg-svn/lib/libc/stdlib/putenv.c (revision 46599)
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*46599Sdonn static char sccsid[] = "@(#)putenv.c	5.4 (Berkeley) 02/23/91";
1036771Sbostic #endif /* LIBC_SCCS and not lint */
1136771Sbostic 
1242137Sbostic #include <stdlib.h>
1342186Sbostic #include <string.h>
1442137Sbostic 
1542186Sbostic int
1636771Sbostic putenv(str)
17*46599Sdonn 	const char *str;
1836771Sbostic {
1942186Sbostic 	register char *p, *equal;
2036771Sbostic 	int rval;
2136771Sbostic 
2242186Sbostic 	if (!(p = strdup(str)))
2336771Sbostic 		return(1);
2442186Sbostic 	if (!(equal = index(p, '='))) {
2542186Sbostic 		(void)free(p);
2642186Sbostic 		return(1);
2742186Sbostic 	}
2836771Sbostic 	*equal = '\0';
2942186Sbostic 	rval = setenv(p, equal + 1, 1);
3042186Sbostic 	(void)free(p);
3136771Sbostic 	return(rval);
3236771Sbostic }
33