aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/environ.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2022-07-28 22:00:40 +0200
committerCorinna Vinschen <corinna@vinschen.de>2022-07-28 22:00:40 +0200
commit7f42498be6cd47e9d3d46ec82374d703e3275ddf (patch)
tree5a9645f5af3bd64039e84f76d9695e91c7741008 /winsup/cygwin/environ.cc
parentcea26c75705b3a56b3f211bb083b8e9afe319e1c (diff)
downloadnewlib-7f42498be6cd47e9d3d46ec82374d703e3275ddf.zip
newlib-7f42498be6cd47e9d3d46ec82374d703e3275ddf.tar.gz
newlib-7f42498be6cd47e9d3d46ec82374d703e3275ddf.tar.bz2
Cygwin: rename __cygwin_environ and drop env redirection via cur_environ()
Back in early Cygwin development a function based access to the environment was exported, the internal environ in Cygwin was called __cygwin_environ and cur_environ() was used to access the environment indirectly . The history of that necessity is not documented, but kept in i686 for backward compatibility. The x86_64 port eventually used __cygwin_environ directly and exported it as DATA under the usual name environ. We don't need the i686 workaround anymore, so just rename __cygwin_environ to environ, drop the cur_environ() macro and simply export environ under its own name. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup/cygwin/environ.cc')
-rw-r--r--winsup/cygwin/environ.cc30
1 files changed, 15 insertions, 15 deletions
diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc
index ca60bd8..0ac1acc 100644
--- a/winsup/cygwin/environ.cc
+++ b/winsup/cygwin/environ.cc
@@ -422,7 +422,7 @@ getwinenv (const char *env, const char *in_posix, win_env *temp)
{
win_env *we = conv_envvars + i;
const char *val;
- if (!cur_environ () || !(val = in_posix ?: getenv (we->name)))
+ if (!environ || !(val = in_posix ?: getenv (we->name)))
debug_printf ("can't set native for %s since no environ yet",
we->name);
else if (!we->posix || strcmp (val, we->posix) != 0)
@@ -486,7 +486,7 @@ my_findenv (const char *name, int *offset)
char **p;
const char *c;
- if (cur_environ () == NULL)
+ if (!environ)
return NULL;
c = name;
@@ -497,11 +497,11 @@ my_findenv (const char *name, int *offset)
len++;
}
- for (p = cur_environ (); *p; ++p)
+ for (p = environ; *p; ++p)
if (!strncmp (*p, name, len))
if (*(c = *p + len) == '=')
{
- *offset = p - cur_environ ();
+ *offset = p - environ;
return (char *) (++c);
}
return NULL;
@@ -602,7 +602,7 @@ _addenv (const char *name, const char *value, int overwrite)
}
else
{ /* Create new slot. */
- int sz = envsize (cur_environ ());
+ int sz = envsize (environ);
/* If sz == 0, we need two new slots, one for the terminating NULL. */
int newsz = sz == 0 ? 2 : sz + 1;
@@ -611,11 +611,11 @@ _addenv (const char *name, const char *value, int overwrite)
offset = newsz - 2;
/* Allocate space for additional element. */
- if (cur_environ () == lastenviron)
- lastenviron = __cygwin_environ = (char **) realloc (lastenviron,
+ if (environ == lastenviron)
+ lastenviron = environ = (char **) realloc (lastenviron,
allocsz);
else if ((lastenviron = (char **) realloc (lastenviron, allocsz)) != NULL)
- __cygwin_environ = (char **) memcpy (lastenviron, __cygwin_environ,
+ environ = (char **) memcpy (lastenviron, environ,
sz * sizeof (char *));
if (!lastenviron)
{
@@ -625,13 +625,13 @@ _addenv (const char *name, const char *value, int overwrite)
return -1; /* Oops. No more memory. */
}
- __cygwin_environ[offset + 1] = NULL; /* NULL terminate. */
+ environ[offset + 1] = NULL; /* NULL terminate. */
}
char *envhere;
if (!issetenv)
/* Not setenv. Just overwrite existing. */
- envhere = cur_environ ()[offset] = (char *) (ENVMALLOC ? strdup (name) : name);
+ envhere = environ[offset] = (char *) (ENVMALLOC ? strdup (name) : name);
else
{ /* setenv */
/* Look for an '=' in the name and ignore anything after that if found. */
@@ -640,7 +640,7 @@ _addenv (const char *name, const char *value, int overwrite)
int namelen = p - name; /* Length of name. */
/* Allocate enough space for name + '=' + value + '\0' */
- envhere = cur_environ ()[offset] = (char *) malloc (namelen + valuelen + 2);
+ envhere = environ[offset] = (char *) malloc (namelen + valuelen + 2);
if (!envhere)
return -1; /* Oops. No more memory. */
@@ -718,7 +718,7 @@ unsetenv (const char *name)
while (my_findenv (name, &offset)) /* if set multiple times */
/* Move up the rest of the array */
- for (e = cur_environ () + offset; ; e++)
+ for (e = environ + offset; ; e++)
if (!(*e = *(e + 1)))
break;
@@ -735,12 +735,12 @@ clearenv (void)
{
__try
{
- if (cur_environ () == lastenviron)
+ if (environ == lastenviron)
{
free (lastenviron);
lastenviron = NULL;
}
- __cygwin_environ = NULL;
+ environ = NULL;
return 0;
}
__except (EFAULT) {}
@@ -842,7 +842,7 @@ environ_init (char **envp, int envc)
out:
findenv_func = (char * (*)(const char*, int*)) my_findenv;
- __cygwin_environ = envp;
+ environ = envp;
if (envp_passed_in)
{
p = getenv ("CYGWIN");