mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-05 12:50:05 +00:00
39d1d4e5ca
1999-10-12 Andreas Jaeger <aj@suse.de> * stdlib/tst-environ.c: Include <string.h> for strcpy declaration. * math/basic-test.c: Fix typo. * locale/programs/xstrdup.c: Include string.h for glibc compilation to get string prototypes. * sysdeps/unix/sysv/linux/alpha/sys/ucontext.h: Add definition of gregset_t and fpregset_t. * sysdeps/generic/s_nexttowardf.c: Add parenthesis to shut up gcc warnings. Correct value for x == 0. * argp/argp-help.c: Remove broken definition of flockfile and funlockfile. 1999-10-12 Andreas Schwab <schwab@suse.de> * sysdeps/unix/sysv/linux/alpha/bits/sigaction.h: Update to match generic Linux version. 1999-10-12 Ulrich Drepper <drepper@cygnus.com> * sysdeps/unix/sysv/linux/bits/sigaction.h: Remove K&R compatibility.
178 lines
4.8 KiB
C
178 lines
4.8 KiB
C
/* Copyright (C) 1999 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Library General Public License as
|
|
published by the Free Software Foundation; either version 2 of the
|
|
License, or (at your option) any later version.
|
|
|
|
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
|
|
Library General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
|
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
Boston, MA 02111-1307, USA. */
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
|
|
#define VAR "FOOBAR"
|
|
|
|
char putenv_val[100] = VAR "=some longer value";
|
|
|
|
int
|
|
main (void)
|
|
{
|
|
int result = 0;
|
|
const char *valp;
|
|
|
|
/* First test: remove entry FOOBAR, whether it exists or not. */
|
|
unsetenv (VAR);
|
|
|
|
/* Now getting the value should fail. */
|
|
if (getenv (VAR) != NULL)
|
|
{
|
|
printf ("There should be no `%s' value\n", VAR);
|
|
result = 1;
|
|
}
|
|
|
|
/* Now add a value, with the replace flag cleared. */
|
|
if (setenv (VAR, "one", 0) != 0)
|
|
{
|
|
printf ("setenv #1 failed: %m\n");
|
|
result = 1;
|
|
}
|
|
|
|
/* Getting this value should now be possible. */
|
|
valp = getenv (VAR);
|
|
if (valp == NULL || strcmp (valp, "one") != 0)
|
|
{
|
|
puts ("getenv #2 failed");
|
|
result = 1;
|
|
}
|
|
|
|
/* Try to replace without the replace flag set. This should fail. */
|
|
if (setenv (VAR, "two", 0) != 0)
|
|
{
|
|
printf ("setenv #2 failed: %m\n");
|
|
result = 1;
|
|
}
|
|
|
|
/* The value shouldn't have changed. */
|
|
valp = getenv (VAR);
|
|
if (valp == NULL || strcmp (valp, "one") != 0)
|
|
{
|
|
puts ("getenv #3 failed");
|
|
result = 1;
|
|
}
|
|
|
|
/* Now replace the value using putenv. */
|
|
if (putenv (putenv_val) != 0)
|
|
{
|
|
printf ("putenv #1 failed: %m\n");
|
|
result = 1;
|
|
}
|
|
|
|
/* The value should have changed now. */
|
|
valp = getenv (VAR);
|
|
if (valp == NULL || strcmp (valp, "some longer value") != 0)
|
|
{
|
|
printf ("getenv #4 failed (is \"%s\")\n", valp);
|
|
result = 1;
|
|
}
|
|
|
|
/* Now one tricky check: changing the variable passed in putenv should
|
|
change the environment. */
|
|
strcpy (&putenv_val[sizeof VAR], "a short one");
|
|
|
|
/* The value should have changed again. */
|
|
valp = getenv (VAR);
|
|
if (valp == NULL || strcmp (valp, "a short one") != 0)
|
|
{
|
|
puts ("getenv #5 failed");
|
|
result = 1;
|
|
}
|
|
|
|
/* It should even be possible to rename the variable. */
|
|
strcpy (putenv_val, "XYZZY=some other value");
|
|
|
|
/* Now a lookup using the old name should fail. */
|
|
if (getenv (VAR) != NULL)
|
|
{
|
|
puts ("getenv #6 failed");
|
|
result = 1;
|
|
}
|
|
|
|
/* But using the new name it should work. */
|
|
valp = getenv ("XYZZY");
|
|
if (valp == NULL || strcmp (valp, "some other value") != 0)
|
|
{
|
|
puts ("getenv #7 failed");
|
|
result = 1;
|
|
}
|
|
|
|
/* Create a new variable with the old name. */
|
|
if (setenv (VAR, "a new value", 0) != 0)
|
|
{
|
|
printf ("setenv #3 failed: %m\n");
|
|
result = 1;
|
|
}
|
|
|
|
/* At this point a getenv call must return the new value. */
|
|
valp = getenv (VAR);
|
|
if (valp == NULL || strcmp (valp, "a new value") != 0)
|
|
{
|
|
puts ("getenv #8 failed");
|
|
result = 1;
|
|
}
|
|
|
|
/* Black magic: rename the variable we added using putenv back. */
|
|
strcpy (putenv_val, VAR "=old name new value");
|
|
|
|
/* This is interesting. We have two variables with the same name.
|
|
Getting a value should return one of them. */
|
|
valp = getenv (VAR);
|
|
if (valp == NULL
|
|
|| (strcmp (valp, "a new value") != 0
|
|
&& strcmp (valp, "old name new value") != 0))
|
|
{
|
|
puts ("getenv #9 failed");
|
|
result = 1;
|
|
}
|
|
|
|
/* More fun ahead: we are now removing the variable. This should remove
|
|
both values. The cast is ok: this call should never put the string
|
|
in the environment and it should never modify it. */
|
|
putenv ((char *) VAR);
|
|
|
|
/* Getting the value should now fail. */
|
|
if (getenv (VAR) != NULL)
|
|
{
|
|
printf ("getenv #10 failed (\"%s\" found)\n", getenv (VAR));
|
|
result = 1;
|
|
}
|
|
|
|
/* Now a test with an environment variable that's one character long.
|
|
This is to test a special case in the getenv implementation. */
|
|
strcpy (putenv_val, "X=one character test");
|
|
if (putenv (putenv_val) != 0)
|
|
{
|
|
printf ("putenv #2 failed: %m\n");
|
|
result = 1;
|
|
}
|
|
|
|
valp = getenv ("X");
|
|
if (valp == NULL || strcmp (valp, "one character test") != 0)
|
|
{
|
|
puts ("getenv #11 failed");
|
|
result = 1;
|
|
}
|
|
|
|
return result;
|
|
}
|