Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meissner <gnu@the-meissners.org>2000-11-22 21:26:10 +0300
committerMichael Meissner <gnu@the-meissners.org>2000-11-22 21:26:10 +0300
commit73dea7905cb5fea2540256bacdfde33fe0ad1a0b (patch)
tree1dd1d4630bf2e207f204657c23319050dbf67c9c /newlib/libc/stdlib/getenv_r.c
parent0217c5bb3b85854cea392d7299706348dc007ae8 (diff)
Only reference environ indirectly through a pointer
Diffstat (limited to 'newlib/libc/stdlib/getenv_r.c')
-rw-r--r--newlib/libc/stdlib/getenv_r.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/newlib/libc/stdlib/getenv_r.c b/newlib/libc/stdlib/getenv_r.c
index 2ccb89a17..dbfcdf54b 100644
--- a/newlib/libc/stdlib/getenv_r.c
+++ b/newlib/libc/stdlib/getenv_r.c
@@ -19,7 +19,7 @@ TRAD_SYNOPSIS
DESCRIPTION
<<_getenv_r>> searches the list of environment variable names and values
-(using the global pointer `<<char **environ>>') for a variable whose
+(using the global pointer ``<<char **environ>>'') for a variable whose
name matches the string at <[name]>. If a variable name matches,
<<_getenv_r>> returns a pointer to the associated value.
@@ -65,6 +65,11 @@ variables vary from one system to another.
extern char **environ;
+/* Only deal with a pointer to environ, to work around subtle bugs with shared
+ libraries and/or small data systems where the user declares his own
+ 'environ'. */
+static char ***p_environ = &environ;
+
/*
* _findenv --
* Returns pointer to value associated with name, if any, else NULL.
@@ -89,7 +94,7 @@ _DEFUN (_findenv_r, (reent_ptr, name, offset),
/* In some embedded systems, this does not get set. This protects
newlib from dereferencing a bad pointer. */
- if (!environ)
+ if (!*p_environ)
return NULL;
c = name;
@@ -100,11 +105,11 @@ _DEFUN (_findenv_r, (reent_ptr, name, offset),
len++;
}
- for (p = environ; *p; ++p)
+ for (p = *p_environ; *p; ++p)
if (!strncmp (*p, name, len))
if (*(c = *p + len) == '=')
{
- *offset = p - environ;
+ *offset = p - *p_environ;
ENV_UNLOCK;
return (char *) (++c);
}