aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/environ.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2000-11-08 20:36:37 +0000
committerChristopher Faylor <me@cgf.cx>2000-11-08 20:36:37 +0000
commit9bc846bd3d5fc13eb28b4ddece0ecfc52caf898a (patch)
tree2fd164536ce8697b5dc316629c913edf27dbdbeb /winsup/cygwin/environ.cc
parent315f8fd37b75a6cfe589afb9eb18cc9bb59874ac (diff)
downloadnewlib-9bc846bd3d5fc13eb28b4ddece0ecfc52caf898a.zip
newlib-9bc846bd3d5fc13eb28b4ddece0ecfc52caf898a.tar.gz
newlib-9bc846bd3d5fc13eb28b4ddece0ecfc52caf898a.tar.bz2
* environ.cc (_addenv): malloc space for setenv if cygwin1.dll is used in
conjunction with older binaries. (environ_init): Ditto. * external.cc (get_cygdrive_info): New function. * external.cc (get_cygdrive_prefixes): Change to use get_cygdrive_info but toss the user and system flags. * external.cc (cygwin_internal): Add new CW_GET_CYGDRIVE_INFO case. * path.cc (mount_info::get_cygdrive_prefixes): Remove method. * path.cc (mount_info::get_cygdrive_info): New method. Actually, get_cygdrive_info is really an enhanced version of get_cygdrive_prefixes renamed to get_cygdrive_info that also gets the user and system flags. * shared_info.h (get_cygdrive_prefixes): Remove method. * shared_info.h (get_cygdrive_info): New method. * include/cygwin/version.h: Bump minor API version due to adding CW_GET_CYGDRIVE_INFO to cygwin_internal. * include/sys/cygwin.h (cygwin_getinfo_types): Add CW_GET_CYGDRIVE_INFO.
Diffstat (limited to 'winsup/cygwin/environ.cc')
-rw-r--r--winsup/cygwin/environ.cc20
1 files changed, 18 insertions, 2 deletions
diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc
index 71acab5..3b67bc7 100644
--- a/winsup/cygwin/environ.cc
+++ b/winsup/cygwin/environ.cc
@@ -24,6 +24,7 @@ details. */
#include "cygheap.h"
#include "registry.h"
#include "environ.h"
+#include "perprocess.h"
extern BOOL allow_glob;
extern BOOL allow_ntea;
@@ -34,6 +35,11 @@ static BOOL envcache = TRUE;
static char **lastenviron = NULL;
+#define ENVMALLOC \
+ (CYGWIN_VERSION_DLL_MAKE_COMBINED (user_data->api_major, user_data->api_minor) \
+ <= CYGWIN_VERSION_DLL_MALLOC_ENV)
+
+
/* List of names which are converted from dos to unix
* on the way in and back again on the way out.
*
@@ -247,8 +253,8 @@ _addenv (const char *name, const char *value, int overwrite)
char *envhere;
if (!issetenv)
- envhere = cur_environ ()[offset] = (char *) name; /* Not setenv. Just
- overwrite existing. */
+ /* Not setenv. Just overwrite existing. */
+ envhere = cur_environ ()[offset] = (char *) (ENVMALLOC ? strdup (name) : name);
else
{ /* setenv */
/* Look for an '=' in the name and ignore anything after that if found. */
@@ -566,7 +572,17 @@ environ_init (char **envp, int envc)
char **newenv = (char **) malloc (envc);
memcpy (newenv, envp, envc);
cfree (envp);
+
+ /* Older applications relied on the fact that cygwin malloced elements of the
+ environment list. */
envp = newenv;
+ if (ENVMALLOC)
+ for (char **e = newenv; *e; e++)
+ {
+ char *p = *e;
+ *e = strdup (p);
+ cfree (p);
+ }
envp_passed_in = 1;
goto out;
}