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:
authorChristopher Faylor <me@cgf.cx>2002-06-29 06:36:08 +0400
committerChristopher Faylor <me@cgf.cx>2002-06-29 06:36:08 +0400
commit094d51931173d399d5719411554e1c61af500bfe (patch)
tree9194597b3e482e0d6990cf543ff7e3cd4f8f0c4f /winsup/cygwin/environ.cc
parent2d5eb17ee38b19b91eaecceb9136885aa4281080 (diff)
* cygheap.h (cygheap_user): Reorg to accommodate environment caching.
(cygheap_user::logsrv): New method. (cygheap_user::winname): Ditto. (cygheap_user::domain): Ditto. (cygheap_user::test_uid): Ditto. * cygheap.cc (cygheap_user::set_name): Reflect name "pwinname" name change. * environ.cc (getwinenveq): New function. (spenv::from_cygheap): Change arguments. (spenv::retrieve): Ditto for call. Use getwinenveq to retrieve info from environment. Always return value from cygwin environment, if it exists. * environ.h (getwinenveq): Declare. * uinfo.cc (cygheap_user::ontherange): Use logsrv() rather than env_logsrv(). (cygheap_user::test_uid): Define new method. (cygheap_user::env_logsrv): Accept environment arguments. Use test_uid to find info. (cygheap_user::env_domain): Ditto. (cygheap_user::env_userprofile): Ditto. (cygheap_user::env_homepath): Ditto. (cygheap_user::env_homedrive): Ditto. (cygheap_user::env_name): Ditto.
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]))