Files
glibc/stdlib/putenv.c
T

73 lines
1.9 KiB
C
Raw Normal View History

1999-07-29 20:40:05 +00:00
/* Copyright (C) 1991, 94, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
1996-11-02 01:28:01 +00:00
This file is part of the GNU C Library.
1995-02-18 01:27:10 +00:00
1996-11-02 01:28:01 +00:00
The GNU C Library is free software; you can redistribute it and/or
2001-07-06 04:58:11 +00:00
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
1995-02-18 01:27:10 +00:00
1996-11-02 01:28:01 +00:00
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2001-07-06 04:58:11 +00:00
Lesser General Public License for more details.
1995-02-18 01:27:10 +00:00
2001-07-06 04:58:11 +00:00
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
1995-02-18 01:27:10 +00:00
1998-05-14 19:14:48 +00:00
#if defined _AIX && !defined __GNUC__
#pragma alloca
#endif
1995-02-18 01:27:10 +00:00
1996-11-02 01:28:01 +00:00
#if HAVE_CONFIG_H
# include <config.h>
1995-02-18 01:27:10 +00:00
#endif
#if _LIBC || HAVE_STDLIB_H
1996-11-02 01:28:01 +00:00
# include <stdlib.h>
1995-02-18 01:27:10 +00:00
#endif
#if _LIBC || HAVE_STRING_H
1996-11-02 01:28:01 +00:00
# include <string.h>
1995-02-18 01:27:10 +00:00
#endif
#if !__GNU_LIBRARY__ && !HAVE_STRCHR
1996-11-02 01:28:01 +00:00
# define strchr index
1995-02-18 01:27:10 +00:00
#endif
#ifndef _LIBC
1996-11-02 01:28:01 +00:00
# ifdef HAVE_ALLOCA_H
# include <alloca.h>
# else
# ifdef __GNUC__
# define alloca __builtin_alloca
# else
extern char *alloca ();
1996-11-02 01:28:01 +00:00
# endif /* __GNUC__ */
# endif /* HAVE_ALLOCA_H */
#endif /* _LIBC */
1995-02-18 01:27:10 +00:00
/* Put STRING, which is of the form "NAME=VALUE", in the environment. */
int
putenv (string)
1999-08-18 07:53:35 +00:00
char *string;
1995-02-18 01:27:10 +00:00
{
const char *const name_end = strchr (string, '=');
1997-11-06 00:02:46 +00:00
if (name_end != NULL)
1995-02-18 01:27:10 +00:00
{
1997-11-06 00:02:46 +00:00
#ifdef _LIBC
1998-05-14 19:14:48 +00:00
char *name = strndupa (string, name_end - string);
1997-11-06 00:02:46 +00:00
#else
1998-05-14 19:14:48 +00:00
char *name = alloca (name_end - string + 1);
memcpy (name, string, name_end - string);
name[name_end - string] = '\0';
1997-11-06 00:02:46 +00:00
#endif
1999-07-29 20:40:05 +00:00
return __add_to_environ (name, NULL, string, 1);
1995-02-18 01:27:10 +00:00
}
1998-07-16 11:44:36 +00:00
__unsetenv (string);
1995-02-18 01:27:10 +00:00
return 0;
}