Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/environ.cc')
-rw-r--r--winsup/cygwin/environ.cc74
1 files changed, 38 insertions, 36 deletions
diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc
index 052398a7f..ae7268fdf 100644
--- a/winsup/cygwin/environ.cc
+++ b/winsup/cygwin/environ.cc
@@ -750,11 +750,43 @@ env_sort (const void *a, const void *b)
return strcmp (*p, *q);
}
+char * __stdcall
+getwinenveq (const char *name, size_t namelen, int x)
+{
+ char dum[1];
+ char name0[namelen - 1];
+ memcpy (name0, name, namelen - 1);
+ name0[namelen - 1] = '\0';
+ int totlen = GetEnvironmentVariable (name0, dum, 0);
+ if (totlen > 0)
+ {
+ totlen++;
+ if (x == HEAP_1_STR)
+ totlen += namelen;
+ else
+ namelen = 0;
+ char *p = (char *) cmalloc ((cygheap_types) x, totlen);
+ if (namelen)
+ strcpy (p, name);
+ if (GetEnvironmentVariable (name0, p + namelen, totlen))
+ {
+ debug_printf ("using value from GetEnvironmentVariable for '%s'",
+ name0);
+ return p;
+ }
+ else
+ cfree (p);
+ }
+
+ debug_printf ("warning: %s not present in environment", name);
+ return NULL;
+}
+
struct spenv
{
const char *name;
size_t namelen;
- const char * (cygheap_user::*from_cygheap) ();
+ const char * (cygheap_user::*from_cygheap) (const char *, size_t);
char *retrieve (bool, const char * const = NULL)
__attribute__ ((regparm (3)));
};
@@ -785,28 +817,15 @@ spenv::retrieve (bool no_envblock, const char *const envname)
if (from_cygheap)
{
const char *p;
- if (cygheap->user.issetuid ())
- debug_printf ("calculating for setuid");
- else
+ if (envname)
{
- debug_printf ("calculating for non-setuid");
- if (!envname)
- {
- debug_printf ("not adding %s to windows environment", name);
- return NULL; /* No need to force these into the
- environment */
- }
-
- if (no_envblock)
- {
- debug_printf ("duping existing value for '%s'", name);
- return cstrdup1 (envname);/* Don't really care what it's set to
+ debug_printf ("duping existing value for '%s'", name);
+ return cstrdup1 (envname); /* Don't really care what it's set to
if we're calling a cygwin program */
- }
}
/* Calculate (potentially) value for given environment variable. */
- p = (cygheap->user.*from_cygheap) ();
+ p = (cygheap->user.*from_cygheap) (name, namelen);
if (!p || (no_envblock && !envname))
return env_dontadd;
char *s = (char *) cmalloc (HEAP_1_STR, namelen + strlen (p) + 1);
@@ -819,24 +838,7 @@ spenv::retrieve (bool no_envblock, const char *const envname)
if (envname)
return cstrdup1 (envname);
- char dum[1];
- int vallen = GetEnvironmentVariable (name, dum, 0);
- if (vallen > 0)
- {
- char *p = (char *) cmalloc (HEAP_1_STR, namelen + ++vallen);
- strcpy (p, name);
- if (GetEnvironmentVariable (name, p + namelen, vallen))
- {
- debug_printf ("using value from GetEnvironmentVariable for '%s'",
- envname);
- return p;
- }
- else
- cfree (p);
- }
-
- debug_printf ("warning: %s not present in environment", name);
- return NULL;
+ return getwinenveq (name, namelen, HEAP_1_STR);
}
#define SPENVS_SIZE (sizeof (spenvs) / sizeof (spenvs[0]))