From 0f1e140e796f55cf5f07d39707f3e88d335f4ff1 Mon Sep 17 00:00:00 2001 From: joseph Date: Wed, 10 Dec 2008 16:39:54 +0000 Subject: Merge changes between r7357 and r7510 from /fsf/trunk. git-svn-id: svn://svn.eglibc.org/trunk@7511 7b3dc134-2b1b-0410-93df-9e9f96275f8d --- libc/stdlib/Makefile | 3 ++- libc/stdlib/setenv.c | 29 +++++++++++++++-------------- libc/stdlib/tst-unsetenv1.c | 12 ++++++++++++ 3 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 libc/stdlib/tst-unsetenv1.c (limited to 'libc/stdlib') diff --git a/libc/stdlib/Makefile b/libc/stdlib/Makefile index 9491229f4..3986ac4a6 100644 --- a/libc/stdlib/Makefile +++ b/libc/stdlib/Makefile @@ -77,7 +77,8 @@ tests := tst-strtol tst-strtod testrand testsort testdiv \ tst-limits tst-rand48 bug-strtod tst-setcontext \ test-a64l tst-qsort tst-system bug-strtod2 \ tst-atof1 tst-atof2 tst-strtod2 tst-rand48-2 \ - tst-makecontext tst-qsort2 tst-makecontext2 tst-strtod6 + tst-makecontext tst-qsort2 tst-makecontext2 tst-strtod6 \ + tst-unsetenv1 tests-$(OPTION_EGLIBC_LOCALE_CODE) \ += tst-strtod3 tst-strtod4 tst-strtod5 testmb2 tests-$(OPTION_POSIX_C_LANG_WIDE_CHAR) \ diff --git a/libc/stdlib/setenv.c b/libc/stdlib/setenv.c index 48aaecffe..fe591b7db 100644 --- a/libc/stdlib/setenv.c +++ b/libc/stdlib/setenv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992,1995-2001,2004 Free Software Foundation, Inc. +/* Copyright (C) 1992,1995-2001,2004, 2008 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 @@ -292,19 +292,20 @@ unsetenv (name) LOCK; ep = __environ; - while (*ep != NULL) - if (!strncmp (*ep, name, len) && (*ep)[len] == '=') - { - /* Found it. Remove this pointer by moving later ones back. */ - char **dp = ep; - - do - dp[0] = dp[1]; - while (*dp++); - /* Continue the loop in case NAME appears again. */ - } - else - ++ep; + if (ep != NULL) + while (*ep != NULL) + if (!strncmp (*ep, name, len) && (*ep)[len] == '=') + { + /* Found it. Remove this pointer by moving later ones back. */ + char **dp = ep; + + do + dp[0] = dp[1]; + while (*dp++); + /* Continue the loop in case NAME appears again. */ + } + else + ++ep; UNLOCK; diff --git a/libc/stdlib/tst-unsetenv1.c b/libc/stdlib/tst-unsetenv1.c new file mode 100644 index 000000000..a2a760d24 --- /dev/null +++ b/libc/stdlib/tst-unsetenv1.c @@ -0,0 +1,12 @@ +#include + +static int +do_test (void) +{ + clearenv (); + unsetenv ("FOO"); + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" -- cgit v1.2.3