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>
This commit is contained in:
parent
cea26c7570
commit
7f42498be6
|
@ -18,6 +18,7 @@ _sys_errlist DATA
|
||||||
_sys_nerr DATA
|
_sys_nerr DATA
|
||||||
_timezone DATA
|
_timezone DATA
|
||||||
_tzname DATA
|
_tzname DATA
|
||||||
|
environ DATA
|
||||||
error_message_count DATA
|
error_message_count DATA
|
||||||
error_one_per_line DATA
|
error_one_per_line DATA
|
||||||
error_print_progname DATA
|
error_print_progname DATA
|
||||||
|
|
|
@ -1002,7 +1002,7 @@ dll_crt0_1 (void *)
|
||||||
sig_dispatch_pending (false);
|
sig_dispatch_pending (false);
|
||||||
_my_tls.call_signal_handler ();
|
_my_tls.call_signal_handler ();
|
||||||
_my_tls.incyg--; /* Not in Cygwin anymore */
|
_my_tls.incyg--; /* Not in Cygwin anymore */
|
||||||
cygwin_exit (user_data->main (__argc, newargv, __cygwin_environ));
|
cygwin_exit (user_data->main (__argc, newargv, environ));
|
||||||
}
|
}
|
||||||
__asm__ (" \n\
|
__asm__ (" \n\
|
||||||
.global _cygwin_exit_return \n\
|
.global _cygwin_exit_return \n\
|
||||||
|
|
|
@ -422,7 +422,7 @@ getwinenv (const char *env, const char *in_posix, win_env *temp)
|
||||||
{
|
{
|
||||||
win_env *we = conv_envvars + i;
|
win_env *we = conv_envvars + i;
|
||||||
const char *val;
|
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",
|
debug_printf ("can't set native for %s since no environ yet",
|
||||||
we->name);
|
we->name);
|
||||||
else if (!we->posix || strcmp (val, we->posix) != 0)
|
else if (!we->posix || strcmp (val, we->posix) != 0)
|
||||||
|
@ -486,7 +486,7 @@ my_findenv (const char *name, int *offset)
|
||||||
char **p;
|
char **p;
|
||||||
const char *c;
|
const char *c;
|
||||||
|
|
||||||
if (cur_environ () == NULL)
|
if (!environ)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
c = name;
|
c = name;
|
||||||
|
@ -497,11 +497,11 @@ my_findenv (const char *name, int *offset)
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (p = cur_environ (); *p; ++p)
|
for (p = environ; *p; ++p)
|
||||||
if (!strncmp (*p, name, len))
|
if (!strncmp (*p, name, len))
|
||||||
if (*(c = *p + len) == '=')
|
if (*(c = *p + len) == '=')
|
||||||
{
|
{
|
||||||
*offset = p - cur_environ ();
|
*offset = p - environ;
|
||||||
return (char *) (++c);
|
return (char *) (++c);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -602,7 +602,7 @@ _addenv (const char *name, const char *value, int overwrite)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ /* Create new slot. */
|
{ /* 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. */
|
/* If sz == 0, we need two new slots, one for the terminating NULL. */
|
||||||
int newsz = sz == 0 ? 2 : sz + 1;
|
int newsz = sz == 0 ? 2 : sz + 1;
|
||||||
|
@ -611,11 +611,11 @@ _addenv (const char *name, const char *value, int overwrite)
|
||||||
offset = newsz - 2;
|
offset = newsz - 2;
|
||||||
|
|
||||||
/* Allocate space for additional element. */
|
/* Allocate space for additional element. */
|
||||||
if (cur_environ () == lastenviron)
|
if (environ == lastenviron)
|
||||||
lastenviron = __cygwin_environ = (char **) realloc (lastenviron,
|
lastenviron = environ = (char **) realloc (lastenviron,
|
||||||
allocsz);
|
allocsz);
|
||||||
else if ((lastenviron = (char **) realloc (lastenviron, allocsz)) != NULL)
|
else if ((lastenviron = (char **) realloc (lastenviron, allocsz)) != NULL)
|
||||||
__cygwin_environ = (char **) memcpy (lastenviron, __cygwin_environ,
|
environ = (char **) memcpy (lastenviron, environ,
|
||||||
sz * sizeof (char *));
|
sz * sizeof (char *));
|
||||||
if (!lastenviron)
|
if (!lastenviron)
|
||||||
{
|
{
|
||||||
|
@ -625,13 +625,13 @@ _addenv (const char *name, const char *value, int overwrite)
|
||||||
return -1; /* Oops. No more memory. */
|
return -1; /* Oops. No more memory. */
|
||||||
}
|
}
|
||||||
|
|
||||||
__cygwin_environ[offset + 1] = NULL; /* NULL terminate. */
|
environ[offset + 1] = NULL; /* NULL terminate. */
|
||||||
}
|
}
|
||||||
|
|
||||||
char *envhere;
|
char *envhere;
|
||||||
if (!issetenv)
|
if (!issetenv)
|
||||||
/* Not setenv. Just overwrite existing. */
|
/* Not setenv. Just overwrite existing. */
|
||||||
envhere = cur_environ ()[offset] = (char *) (ENVMALLOC ? strdup (name) : name);
|
envhere = environ[offset] = (char *) (ENVMALLOC ? strdup (name) : name);
|
||||||
else
|
else
|
||||||
{ /* setenv */
|
{ /* setenv */
|
||||||
/* Look for an '=' in the name and ignore anything after that if found. */
|
/* 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. */
|
int namelen = p - name; /* Length of name. */
|
||||||
/* Allocate enough space for name + '=' + value + '\0' */
|
/* 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)
|
if (!envhere)
|
||||||
return -1; /* Oops. No more memory. */
|
return -1; /* Oops. No more memory. */
|
||||||
|
|
||||||
|
@ -718,7 +718,7 @@ unsetenv (const char *name)
|
||||||
|
|
||||||
while (my_findenv (name, &offset)) /* if set multiple times */
|
while (my_findenv (name, &offset)) /* if set multiple times */
|
||||||
/* Move up the rest of the array */
|
/* Move up the rest of the array */
|
||||||
for (e = cur_environ () + offset; ; e++)
|
for (e = environ + offset; ; e++)
|
||||||
if (!(*e = *(e + 1)))
|
if (!(*e = *(e + 1)))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -735,12 +735,12 @@ clearenv (void)
|
||||||
{
|
{
|
||||||
__try
|
__try
|
||||||
{
|
{
|
||||||
if (cur_environ () == lastenviron)
|
if (environ == lastenviron)
|
||||||
{
|
{
|
||||||
free (lastenviron);
|
free (lastenviron);
|
||||||
lastenviron = NULL;
|
lastenviron = NULL;
|
||||||
}
|
}
|
||||||
__cygwin_environ = NULL;
|
environ = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
__except (EFAULT) {}
|
__except (EFAULT) {}
|
||||||
|
@ -842,7 +842,7 @@ environ_init (char **envp, int envc)
|
||||||
|
|
||||||
out:
|
out:
|
||||||
findenv_func = (char * (*)(const char*, int*)) my_findenv;
|
findenv_func = (char * (*)(const char*, int*)) my_findenv;
|
||||||
__cygwin_environ = envp;
|
environ = envp;
|
||||||
if (envp_passed_in)
|
if (envp_passed_in)
|
||||||
{
|
{
|
||||||
p = getenv ("CYGWIN");
|
p = getenv ("CYGWIN");
|
||||||
|
|
|
@ -33,8 +33,6 @@ struct win_env
|
||||||
win_env *getwinenv (const char *name, const char *posix = NULL, win_env * = NULL);
|
win_env *getwinenv (const char *name, const char *posix = NULL, win_env * = NULL);
|
||||||
char *getwinenveq (const char *name, size_t len, int);
|
char *getwinenveq (const char *name, size_t len, int);
|
||||||
|
|
||||||
extern "C" char **__cygwin_environ;
|
|
||||||
#define cur_environ() __cygwin_environ
|
|
||||||
char **build_env (const char * const *envp, PWCHAR &envblock,
|
char **build_env (const char * const *envp, PWCHAR &envblock,
|
||||||
int &envc, bool need_envblock, HANDLE new_token);
|
int &envc, bool need_envblock, HANDLE new_token);
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ execl (const char *path, const char *arg0, ...)
|
||||||
argv[i] = va_arg (args, const char *);
|
argv[i] = va_arg (args, const char *);
|
||||||
while (argv[i++] != NULL);
|
while (argv[i++] != NULL);
|
||||||
va_end (args);
|
va_end (args);
|
||||||
return spawnve (_P_OVERLAY, path, (char * const *) argv, cur_environ ());
|
return spawnve (_P_OVERLAY, path, (char * const *) argv, environ);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int
|
extern "C" int
|
||||||
|
@ -71,13 +71,13 @@ execlp (const char *file, const char *arg0, ...)
|
||||||
va_end (args);
|
va_end (args);
|
||||||
return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC,
|
return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC,
|
||||||
find_exec (file, buf, "PATH", FE_NNF) ?: "",
|
find_exec (file, buf, "PATH", FE_NNF) ?: "",
|
||||||
(char * const *) argv, cur_environ ());
|
(char * const *) argv, environ);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int
|
extern "C" int
|
||||||
execv (const char *path, char * const *argv)
|
execv (const char *path, char * const *argv)
|
||||||
{
|
{
|
||||||
return spawnve (_P_OVERLAY, path, argv, cur_environ ());
|
return spawnve (_P_OVERLAY, path, argv, environ);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int
|
extern "C" int
|
||||||
|
@ -94,7 +94,7 @@ execvp (const char *file, char * const *argv)
|
||||||
|
|
||||||
return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC,
|
return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC,
|
||||||
find_exec (file, buf, "PATH", FE_NNF) ?: "",
|
find_exec (file, buf, "PATH", FE_NNF) ?: "",
|
||||||
argv, cur_environ ());
|
argv, environ);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int
|
extern "C" int
|
||||||
|
|
|
@ -140,7 +140,7 @@ create_winenv (const char * const *env)
|
||||||
{
|
{
|
||||||
int unused_envc;
|
int unused_envc;
|
||||||
PWCHAR envblock = NULL;
|
PWCHAR envblock = NULL;
|
||||||
char **envp = build_env (env ?: cur_environ (), envblock, unused_envc, false,
|
char **envp = build_env (env ?: environ, envblock, unused_envc, false,
|
||||||
NULL);
|
NULL);
|
||||||
PWCHAR p = envblock;
|
PWCHAR p = envblock;
|
||||||
|
|
||||||
|
|
|
@ -155,9 +155,7 @@ const int __collate_load_error = 0;
|
||||||
extern UNICODE_STRING _RDATA ro_u_mq_suffix = _ROU (L":mqueue");
|
extern UNICODE_STRING _RDATA ro_u_mq_suffix = _ROU (L":mqueue");
|
||||||
#undef _ROU
|
#undef _ROU
|
||||||
|
|
||||||
/* This is an exported copy of environ which can be used by DLLs
|
char **environ;
|
||||||
which use cygwin.dll. */
|
|
||||||
char **__cygwin_environ;
|
|
||||||
/* __progname used in getopt error message */
|
/* __progname used in getopt error message */
|
||||||
char *__progname;
|
char *__progname;
|
||||||
char *program_invocation_name;
|
char *program_invocation_name;
|
||||||
|
|
|
@ -769,7 +769,7 @@ commune_process (void *arg)
|
||||||
{
|
{
|
||||||
sigproc_printf ("processing PICOM_ENVIRON");
|
sigproc_printf ("processing PICOM_ENVIRON");
|
||||||
unsigned n = 0;
|
unsigned n = 0;
|
||||||
char **env = cur_environ ();
|
char **env = environ;
|
||||||
if (env)
|
if (env)
|
||||||
for (char **e = env; *e; e++)
|
for (char **e = env; *e; e++)
|
||||||
n += strlen (*e) + 1;
|
n += strlen (*e) + 1;
|
||||||
|
@ -1210,7 +1210,7 @@ _pinfo::environ (size_t& n)
|
||||||
return cr.s;
|
return cr.s;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
env = cur_environ ();
|
env = ::environ;
|
||||||
|
|
||||||
if (env == NULL)
|
if (env == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -1130,7 +1130,7 @@ spawnl (int mode, const char *path, const char *arg0, ...)
|
||||||
|
|
||||||
va_end (args);
|
va_end (args);
|
||||||
|
|
||||||
return spawnve (mode, path, (char * const *) argv, cur_environ ());
|
return spawnve (mode, path, (char * const *) argv, environ);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int
|
extern "C" int
|
||||||
|
@ -1174,7 +1174,7 @@ spawnlp (int mode, const char *file, const char *arg0, ...)
|
||||||
va_end (args);
|
va_end (args);
|
||||||
|
|
||||||
return spawnve (mode | _P_PATH_TYPE_EXEC, find_exec (file, buf),
|
return spawnve (mode | _P_PATH_TYPE_EXEC, find_exec (file, buf),
|
||||||
(char * const *) argv, cur_environ ());
|
(char * const *) argv, environ);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int
|
extern "C" int
|
||||||
|
@ -1204,7 +1204,7 @@ spawnlpe (int mode, const char *file, const char *arg0, ...)
|
||||||
extern "C" int
|
extern "C" int
|
||||||
spawnv (int mode, const char *path, const char * const *argv)
|
spawnv (int mode, const char *path, const char * const *argv)
|
||||||
{
|
{
|
||||||
return spawnve (mode, path, argv, cur_environ ());
|
return spawnve (mode, path, argv, environ);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int
|
extern "C" int
|
||||||
|
@ -1213,7 +1213,7 @@ spawnvp (int mode, const char *file, const char * const *argv)
|
||||||
path_conv buf;
|
path_conv buf;
|
||||||
return spawnve (mode | _P_PATH_TYPE_EXEC,
|
return spawnve (mode | _P_PATH_TYPE_EXEC,
|
||||||
find_exec (file, buf, "PATH", FE_NNF) ?: "",
|
find_exec (file, buf, "PATH", FE_NNF) ?: "",
|
||||||
argv, cur_environ ());
|
argv, environ);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int
|
extern "C" int
|
||||||
|
|
|
@ -4372,7 +4372,7 @@ popen (const char *command, const char *in_type)
|
||||||
fcntl (stdchild, F_SETFD, stdchild_state | FD_CLOEXEC);
|
fcntl (stdchild, F_SETFD, stdchild_state | FD_CLOEXEC);
|
||||||
|
|
||||||
/* Start a shell process to run the given command without forking. */
|
/* Start a shell process to run the given command without forking. */
|
||||||
pid_t pid = ch_spawn.worker ("/bin/sh", argv, cur_environ (), _P_NOWAIT,
|
pid_t pid = ch_spawn.worker ("/bin/sh", argv, environ, _P_NOWAIT,
|
||||||
__std[0], __std[1]);
|
__std[0], __std[1]);
|
||||||
|
|
||||||
/* Reinstate the close-on-exec state */
|
/* Reinstate the close-on-exec state */
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
LIBRARY "cygwin1.dll" BASE=0x180040000
|
LIBRARY "cygwin1.dll" BASE=0x180040000
|
||||||
|
|
||||||
EXPORTS
|
EXPORTS
|
||||||
#Exported variables
|
|
||||||
environ = __cygwin_environ DATA
|
|
||||||
|
|
||||||
#Exported functions
|
#Exported functions
|
||||||
__wrap__Znam NOSIGFE # void *operator new[](std::size_t sz) throw (std::bad_alloc)
|
__wrap__Znam NOSIGFE # void *operator new[](std::size_t sz) throw (std::bad_alloc)
|
||||||
__wrap__ZnamRKSt9nothrow_t NOSIGFE # void *operator new[](std::size_t sz, const std::nothrow_t &nt) throw()
|
__wrap__ZnamRKSt9nothrow_t NOSIGFE # void *operator new[](std::size_t sz, const std::nothrow_t &nt) throw()
|
||||||
|
|
Loading…
Reference in New Issue