From 8dfce03bfaae529e872ddfa39b5879ae6a9fdf06 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 5 Oct 2011 12:27:37 +0000 Subject: [PATCH] * external.cc (create_winenv): Rename from sync_winenv. Take environment pointer as parameter and return pointer to corresponding win32 environment block if != NULL. Otherwise just sync as before. (cygwin_internal): Add CW_CVT_ENV_TO_WINENV case. * include/cygwin/version.h: Bump API minor number. * include/sys/cygwin.h (cygwin_getinfo_types): Add CW_CVT_ENV_TO_WINENV. --- winsup/cygwin/ChangeLog | 9 +++++++++ winsup/cygwin/external.cc | 22 +++++++++++++++++----- winsup/cygwin/include/cygwin/version.h | 3 ++- winsup/cygwin/include/sys/cygwin.h | 3 ++- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 99a372c11..08d7a3cab 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,12 @@ +2011-10-05 Corinna Vinschen + + * external.cc (create_winenv): Rename from sync_winenv. Take + environment pointer as parameter and return pointer to corresponding + win32 environment block if != NULL. Otherwise just sync as before. + (cygwin_internal): Add CW_CVT_ENV_TO_WINENV case. + * include/cygwin/version.h: Bump API minor number. + * include/sys/cygwin.h (cygwin_getinfo_types): Add CW_CVT_ENV_TO_WINENV. + 2011-10-04 Corinna Vinschen * net.cc (socketpair): Bind first socket to loopback only as well. diff --git a/winsup/cygwin/external.cc b/winsup/cygwin/external.cc index d818cbc78..35f0f0909 100644 --- a/winsup/cygwin/external.cc +++ b/winsup/cygwin/external.cc @@ -132,12 +132,12 @@ check_ntsec (const char *filename) } /* Copy cygwin environment variables to the Windows environment. */ -static void -sync_winenv () +static PWCHAR +create_winenv (const char * const *env) { int unused_envc; PWCHAR envblock = NULL; - char **envp = build_env (cur_environ (), envblock, unused_envc, false); + char **envp = build_env (env ?: cur_environ (), envblock, unused_envc, false); PWCHAR p = envblock; if (envp) @@ -146,8 +146,12 @@ sync_winenv () cfree (*e); cfree (envp); } + /* If we got an env block, just return pointer to win env. */ + if (env) + return envblock; + /* Otherwise sync win env of current process with its posix env. */ if (!p) - return; + return NULL; while (*p) { PWCHAR eq = wcschr (p, L'='); @@ -160,6 +164,7 @@ sync_winenv () p = wcschr (p, L'\0') + 1; } free (envblock); + return NULL; } /* @@ -419,7 +424,7 @@ cygwin_internal (cygwin_getinfo_types t, ...) try_to_debug (); break; case CW_SYNC_WINENV: - sync_winenv (); + create_winenv (NULL); res = 0; break; case CW_CYGTLS_PADSIZE: @@ -516,6 +521,13 @@ cygwin_internal (cygwin_getinfo_types t, ...) } break; + case CW_CVT_ENV_TO_WINENV: + { + char **posix_env = va_arg (arg, char **); + res = (uintptr_t) create_winenv (posix_env); + } + break; + default: set_errno (ENOSYS); } diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index 437ebe45a..1dcf53885 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -420,12 +420,13 @@ details. */ 249: Export pthread_condattr_getclock, pthread_condattr_setclock. 250: Export clock_nanosleep. 251: RTLD_NODELETE, RTLD_NOLOAD, RTLD_DEEPBIND added. + 252: CW_CVT_ENV_TO_WINENV added. */ /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */ #define CYGWIN_VERSION_API_MAJOR 0 -#define CYGWIN_VERSION_API_MINOR 251 +#define CYGWIN_VERSION_API_MINOR 252 /* There is also a compatibity version number associated with the shared memory regions. It is incremented when incompatible diff --git a/winsup/cygwin/include/sys/cygwin.h b/winsup/cygwin/include/sys/cygwin.h index d541bd519..742861836 100644 --- a/winsup/cygwin/include/sys/cygwin.h +++ b/winsup/cygwin/include/sys/cygwin.h @@ -134,7 +134,8 @@ typedef enum CW_INT_SETLOCALE, CW_CVT_MNT_OPTS, CW_LST_MNT_OPTS, - CW_STRERROR + CW_STRERROR, + CW_CVT_ENV_TO_WINENV } cygwin_getinfo_types; /* Token type for CW_SET_EXTERNAL_TOKEN */