Return-Path: Delivered-To: apmail-incubator-stdcxx-commits-archive@www.apache.org Received: (qmail 16734 invoked from network); 10 Oct 2006 01:40:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 10 Oct 2006 01:40:59 -0000 Received: (qmail 23026 invoked by uid 500); 10 Oct 2006 01:40:51 -0000 Delivered-To: apmail-incubator-stdcxx-commits-archive@incubator.apache.org Received: (qmail 23013 invoked by uid 500); 10 Oct 2006 01:40:51 -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 22826 invoked by uid 99); 10 Oct 2006 01:40:49 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Oct 2006 18:40:49 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Oct 2006 18:40:46 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id ACD1D1A981A; Mon, 9 Oct 2006 18:40:25 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r454583 - /incubator/stdcxx/trunk/tests/src/environ.cpp Date: Tue, 10 Oct 2006 01:40:25 -0000 To: stdcxx-commits@incubator.apache.org From: sebor@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061010014025.ACD1D1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: sebor Date: Mon Oct 9 18:40:25 2006 New Revision: 454583 URL: http://svn.apache.org/viewvc?view=rev&rev=454583 Log: 2006-10-09 Martin Sebor * environ.cpp (unsetenv): Conditionally declared. (rw_putenv): Handled invalid separator character. Handled malloc() failure to allocate memory. Used unsetenv() when available, otherwise putenv(). Modified: incubator/stdcxx/trunk/tests/src/environ.cpp Modified: incubator/stdcxx/trunk/tests/src/environ.cpp URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/environ.cpp?view=diff&rev=454583&r1=454582&r2=454583 ============================================================================== --- incubator/stdcxx/trunk/tests/src/environ.cpp (original) +++ incubator/stdcxx/trunk/tests/src/environ.cpp Mon Oct 9 18:40:25 2006 @@ -6,22 +6,23 @@ * ************************************************************************ * - * Copyright 2005-2006 The Apache Software Foundation or its licensors, - * as applicable. + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you 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 * - * 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 + * 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. + * 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 2001-2006 Rogue Wave Software. * **************************************************************************/ @@ -49,6 +50,17 @@ #endif // _RWSTD_NO_PUTENV_CONST_CHAR + +#ifdef _RWSTD_NO_UNSETENV +# ifndef _RWSTD_NO_UNSETENV_IN_LIBC + +_RWSTD_DLLIMPORT int unsetenv (const char*) _LIBC_THROWS (); + +# undef _RWSTD_NO_UNSETENV + +# endif // _RWSTD_NO_UNSETENV_IN_LIBC +#endif // _RWSTD_NO_UNSETENV + } // extern "C" @@ -67,10 +79,14 @@ return 0; } + // set separator to NUL if it's invalid + if (sep < 0 || int (_RWSTD_UCHAR_MAX) < sep) + sep = 0; + for (const char *pvar = str; pvar && *pvar; ++nset) { - const char *pend = - sep < int (_RWSTD_UCHAR_MAX) ? strchr (pvar, sep) : 0; + // look for separator (or the terminating NUL by default) + const char *pend = strchr (pvar, sep); if (0 == pend) pend = pvar + strlen (pvar); @@ -78,6 +94,9 @@ const size_t varlen = pend - pvar; char* const envvar = (char*)malloc (pend - pvar + 1); + if (0 == envvar) + return -1; + memcpy (envvar, pvar, varlen); envvar [varlen] = '\0'; @@ -113,7 +132,12 @@ } else if ((var = getenv (envvar))) { // try to remove variable from the environment + +#ifndef _RWSTD_NO_UNSETENV + ret = unsetenv (envvar) +#else ret = putenv (envvar); +#endif if (0 == ret) { // see if the variable has been removed