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 <[EMAIL PROTECTED]>
* 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