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
|
||||
_timezone DATA
|
||||
_tzname DATA
|
||||
environ DATA
|
||||
error_message_count DATA
|
||||
error_one_per_line DATA
|
||||
error_print_progname DATA
|
||||
|
|
|
@ -1002,7 +1002,7 @@ dll_crt0_1 (void *)
|
|||
sig_dispatch_pending (false);
|
||||
_my_tls.call_signal_handler ();
|
||||
_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\
|
||||
.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;
|
||||
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");
|
||||
|
|
|
@ -33,8 +33,6 @@ struct win_env
|
|||
win_env *getwinenv (const char *name, const char *posix = NULL, win_env * = NULL);
|
||||
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,
|
||||
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 *);
|
||||
while (argv[i++] != NULL);
|
||||
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
|
||||
|
@ -71,13 +71,13 @@ execlp (const char *file, const char *arg0, ...)
|
|||
va_end (args);
|
||||
return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC,
|
||||
find_exec (file, buf, "PATH", FE_NNF) ?: "",
|
||||
(char * const *) argv, cur_environ ());
|
||||
(char * const *) argv, environ);
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
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
|
||||
|
@ -94,7 +94,7 @@ execvp (const char *file, char * const *argv)
|
|||
|
||||
return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC,
|
||||
find_exec (file, buf, "PATH", FE_NNF) ?: "",
|
||||
argv, cur_environ ());
|
||||
argv, environ);
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
|
|
|
@ -140,7 +140,7 @@ create_winenv (const char * const *env)
|
|||
{
|
||||
int unused_envc;
|
||||
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);
|
||||
PWCHAR p = envblock;
|
||||
|
||||
|
|
|
@ -155,9 +155,7 @@ const int __collate_load_error = 0;
|
|||
extern UNICODE_STRING _RDATA ro_u_mq_suffix = _ROU (L":mqueue");
|
||||
#undef _ROU
|
||||
|
||||
/* This is an exported copy of environ which can be used by DLLs
|
||||
which use cygwin.dll. */
|
||||
char **__cygwin_environ;
|
||||
char **environ;
|
||||
/* __progname used in getopt error message */
|
||||
char *__progname;
|
||||
char *program_invocation_name;
|
||||
|
|
|
@ -769,7 +769,7 @@ commune_process (void *arg)
|
|||
{
|
||||
sigproc_printf ("processing PICOM_ENVIRON");
|
||||
unsigned n = 0;
|
||||
char **env = cur_environ ();
|
||||
char **env = environ;
|
||||
if (env)
|
||||
for (char **e = env; *e; e++)
|
||||
n += strlen (*e) + 1;
|
||||
|
@ -1210,7 +1210,7 @@ _pinfo::environ (size_t& n)
|
|||
return cr.s;
|
||||
}
|
||||
else
|
||||
env = cur_environ ();
|
||||
env = ::environ;
|
||||
|
||||
if (env == NULL)
|
||||
return NULL;
|
||||
|
|
|
@ -1130,7 +1130,7 @@ spawnl (int mode, const char *path, const char *arg0, ...)
|
|||
|
||||
va_end (args);
|
||||
|
||||
return spawnve (mode, path, (char * const *) argv, cur_environ ());
|
||||
return spawnve (mode, path, (char * const *) argv, environ);
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
|
@ -1174,7 +1174,7 @@ spawnlp (int mode, const char *file, const char *arg0, ...)
|
|||
va_end (args);
|
||||
|
||||
return spawnve (mode | _P_PATH_TYPE_EXEC, find_exec (file, buf),
|
||||
(char * const *) argv, cur_environ ());
|
||||
(char * const *) argv, environ);
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
|
@ -1204,7 +1204,7 @@ spawnlpe (int mode, const char *file, const char *arg0, ...)
|
|||
extern "C" int
|
||||
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
|
||||
|
@ -1213,7 +1213,7 @@ spawnvp (int mode, const char *file, const char * const *argv)
|
|||
path_conv buf;
|
||||
return spawnve (mode | _P_PATH_TYPE_EXEC,
|
||||
find_exec (file, buf, "PATH", FE_NNF) ?: "",
|
||||
argv, cur_environ ());
|
||||
argv, environ);
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
|
|
|
@ -4372,7 +4372,7 @@ popen (const char *command, const char *in_type)
|
|||
fcntl (stdchild, F_SETFD, stdchild_state | FD_CLOEXEC);
|
||||
|
||||
/* 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]);
|
||||
|
||||
/* Reinstate the close-on-exec state */
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
LIBRARY "cygwin1.dll" BASE=0x180040000
|
||||
|
||||
EXPORTS
|
||||
#Exported variables
|
||||
environ = __cygwin_environ DATA
|
||||
|
||||
#Exported functions
|
||||
__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()
|
||||
|
|
Loading…
Reference in New Issue