From stdcxx-commits-return-592-apmail-incubator-stdcxx-commits-archive=incubator.apache.org@incubator.apache.org Fri Mar 31 01:55:35 2006 Return-Path: Delivered-To: apmail-incubator-stdcxx-commits-archive@www.apache.org Received: (qmail 74430 invoked from network); 31 Mar 2006 01:55:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 31 Mar 2006 01:55:34 -0000 Received: (qmail 86138 invoked by uid 500); 31 Mar 2006 01:55:34 -0000 Delivered-To: apmail-incubator-stdcxx-commits-archive@incubator.apache.org Received: (qmail 86123 invoked by uid 500); 31 Mar 2006 01:55:34 -0000 Mailing-List: contact stdcxx-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-commits@incubator.apache.org Received: (qmail 86112 invoked by uid 99); 31 Mar 2006 01:55:34 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Mar 2006 17:55:33 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 30 Mar 2006 17:55:33 -0800 Received: (qmail 74352 invoked by uid 65534); 31 Mar 2006 01:55:12 -0000 Message-ID: <20060331015512.74349.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r390297 - /incubator/stdcxx/trunk/tests/src/environ.cpp Date: Fri, 31 Mar 2006 01:55:12 -0000 To: stdcxx-commits@incubator.apache.org From: sebor@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: sebor Date: Thu Mar 30 17:55:11 2006 New Revision: 390297 URL: http://svn.apache.org/viewcvs?rev=390297&view=rev Log: 2006-03-30 Martin Sebor * environ.cpp (rw_putenv): Removed the variable from the environment when it doesn't contain the equals sign. Modified: incubator/stdcxx/trunk/tests/src/environ.cpp Modified: incubator/stdcxx/trunk/tests/src/environ.cpp URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/environ.cpp?rev=390297&r1=390296&r2=390297&view=diff ============================================================================== --- incubator/stdcxx/trunk/tests/src/environ.cpp (original) +++ incubator/stdcxx/trunk/tests/src/environ.cpp Thu Mar 30 17:55:11 2006 @@ -6,16 +6,22 @@ * ************************************************************************ * - * Copyright (c) 1994-2005 Quovadx, Inc., acting through its Rogue Wave - * Software division. Licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. Unless required by - * applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License - * for the specific language governing permissions and limitations under - * the License. + * Copyright 2005-2006 The Apache Software Foundation or its licensors, + * as applicable. + * + * Copyright 2001-2006 Rogue Wave Software. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. * **************************************************************************/ @@ -31,6 +37,8 @@ extern "C" { +// char** environ; + #ifndef _RWSTD_NO_PUTENV_CONST_CHAR _RWSTD_DLLIMPORT int putenv (const char*) _LIBC_THROWS (); @@ -44,7 +52,7 @@ } // extern "C" -// sets one or more sep-separated environment variables +// sets (or unsets) one or more sep-separated environment variables _TEST_EXPORT int rw_putenv (const char* str, int sep /* = -1 */) { @@ -61,8 +69,10 @@ for (const char *pvar = str; pvar && *pvar; ++nset) { - const char *pend = strchr (pvar, sep); - if (!pend) + const char *pend = + sep < int (_RWSTD_UCHAR_MAX) ? strchr (pvar, sep) : 0; + + if (0 == pend) pend = pvar + strlen (pvar); const size_t varlen = pend - pvar; @@ -71,31 +81,68 @@ memcpy (envvar, pvar, varlen); envvar [varlen] = '\0'; - // Note: calling Solaris 7 putenv() during program startup - // (i.e., from ctors of namespace-scope objects) prevents - // getenv() from finding that variable at program runtime - ret = putenv (envvar); - - // determine wheteher putenv() made copy of the variable - // or if it simply used the pointer passed to it; if the - // former, deallocate the buffer dynamically allocated - // above + // look for the first equals sign + const char* const equals = strchr (envvar, '='); + + char *var = 0; - char namebuf [256]; - char* const equals = strchr (envvar, '='); if (equals) { + // add the variable to the environment or modify it if + // it's already defined + + // Note: calling Solaris 7 putenv() during program startup + // (i.e., from ctors of namespace-scope objects) prevents + // getenv() from finding that variable at program runtime + ret = putenv (envvar); + + // determine wheteher putenv() made copy of the variable + // or if it simply used the pointer passed to it; if the + // former, deallocate the buffer dynamically allocated + // above + + char namebuf [256]; assert (size_t (equals - envvar) < sizeof namebuf); memcpy (namebuf, envvar, equals - envvar); namebuf [equals - envvar] = '\0'; - const char* const var = getenv (namebuf); + var = getenv (namebuf); if (equals + 1 != var) free (envvar); } - else + else if ((var = getenv (envvar))) { + // try to remove variable from the environment + ret = putenv (envvar); + + if (0 == ret) { + // see if the variable has been removed + var = getenv (envvar); + if (var) { + // if not, zero-out the first byte of its name + // FIXME: make this more robust, e.g., by calling + // unsetenv() when provided or by manipulating + // the environment directly + *(var - 1 - varlen) = '\0'; + +#if 0 // disabled + + char **penv = environ; + if (penv) { + while (*penv && *penv != (var - 1 - varlen)) + ++penv; + + while (*penv) + *penv = penv [1]; + } + +#endif // 0/1 + + } + } + free (envvar); + } pvar = pend + !!*pend; }