mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-01-18 12:29:32 +08:00
Changes suggested by Pierre Humblet.
* environ.cc (NL): New macro. (conv_envvars): Use NL macro to fill in name and namelen. (spenv::namelen): New field. (spenvs): Use NL to fill in name and namelen. (spenv::retrieve): Eliminate length argument. Instead, use namelen throughout. (build_env): Don't calculate length of initial FOO= part of environment. Accommodate spenv::retrive argument change.
This commit is contained in:
parent
5f25e1d11a
commit
a05a9e0123
@ -1,3 +1,15 @@
|
|||||||
|
2002-06-16 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
|
Changes suggested by Pierre Humblet.
|
||||||
|
* environ.cc (NL): New macro.
|
||||||
|
(conv_envvars): Use NL macro to fill in name and namelen.
|
||||||
|
(spenv::namelen): New field.
|
||||||
|
(spenvs): Use NL to fill in name and namelen.
|
||||||
|
(spenv::retrieve): Eliminate length argument. Instead, use namelen
|
||||||
|
throughout.
|
||||||
|
(build_env): Don't calculate length of initial FOO= part of
|
||||||
|
environment. Accommodate spenv::retrive argument change.
|
||||||
|
|
||||||
2002-06-16 Christopher Faylor <cgf@redhat.com>
|
2002-06-16 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
* cygheap.h (cygheap_user::winname): New field.
|
* cygheap.h (cygheap_user::winname): New field.
|
||||||
|
@ -44,6 +44,7 @@ static char **lastenviron;
|
|||||||
(CYGWIN_VERSION_DLL_MAKE_COMBINED (user_data->api_major, user_data->api_minor) \
|
(CYGWIN_VERSION_DLL_MAKE_COMBINED (user_data->api_major, user_data->api_minor) \
|
||||||
<= CYGWIN_VERSION_DLL_MALLOC_ENV)
|
<= CYGWIN_VERSION_DLL_MALLOC_ENV)
|
||||||
|
|
||||||
|
#define NL(x) x, (sizeof (x) - 1)
|
||||||
/* List of names which are converted from dos to unix
|
/* List of names which are converted from dos to unix
|
||||||
on the way in and back again on the way out.
|
on the way in and back again on the way out.
|
||||||
|
|
||||||
@ -53,19 +54,19 @@ static char **lastenviron;
|
|||||||
static int return_MAX_PATH (const char *) {return MAX_PATH;}
|
static int return_MAX_PATH (const char *) {return MAX_PATH;}
|
||||||
static NO_COPY win_env conv_envvars[] =
|
static NO_COPY win_env conv_envvars[] =
|
||||||
{
|
{
|
||||||
{"PATH=", 5, NULL, NULL, cygwin_win32_to_posix_path_list,
|
{NL ("PATH="), NULL, NULL, cygwin_win32_to_posix_path_list,
|
||||||
cygwin_posix_to_win32_path_list,
|
cygwin_posix_to_win32_path_list,
|
||||||
cygwin_win32_to_posix_path_list_buf_size,
|
cygwin_win32_to_posix_path_list_buf_size,
|
||||||
cygwin_posix_to_win32_path_list_buf_size},
|
cygwin_posix_to_win32_path_list_buf_size},
|
||||||
{"HOME=", 5, NULL, NULL, cygwin_conv_to_full_posix_path, cygwin_conv_to_full_win32_path,
|
{NL ("HOME="), NULL, NULL, cygwin_conv_to_full_posix_path, cygwin_conv_to_full_win32_path,
|
||||||
return_MAX_PATH, return_MAX_PATH},
|
return_MAX_PATH, return_MAX_PATH},
|
||||||
{"LD_LIBRARY_PATH=", 16, NULL, NULL, cygwin_conv_to_full_posix_path,
|
{NL ("LD_LIBRARY_PATH="), NULL, NULL, cygwin_conv_to_full_posix_path,
|
||||||
cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH},
|
cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH},
|
||||||
{"TMPDIR=", 7, NULL, NULL, cygwin_conv_to_full_posix_path, cygwin_conv_to_full_win32_path,
|
{NL ("TMPDIR="), NULL, NULL, cygwin_conv_to_full_posix_path, cygwin_conv_to_full_win32_path,
|
||||||
return_MAX_PATH, return_MAX_PATH},
|
return_MAX_PATH, return_MAX_PATH},
|
||||||
{"TMP=", 4, NULL, NULL, cygwin_conv_to_full_posix_path, cygwin_conv_to_full_win32_path,
|
{NL ("TMP="), NULL, NULL, cygwin_conv_to_full_posix_path, cygwin_conv_to_full_win32_path,
|
||||||
return_MAX_PATH, return_MAX_PATH},
|
return_MAX_PATH, return_MAX_PATH},
|
||||||
{"TEMP=", 5, NULL, NULL, cygwin_conv_to_full_posix_path, cygwin_conv_to_full_win32_path,
|
{NL ("TEMP="), NULL, NULL, cygwin_conv_to_full_posix_path, cygwin_conv_to_full_win32_path,
|
||||||
return_MAX_PATH, return_MAX_PATH},
|
return_MAX_PATH, return_MAX_PATH},
|
||||||
{NULL, 0, NULL, NULL, NULL, NULL, 0, 0}
|
{NULL, 0, NULL, NULL, NULL, NULL, 0, 0}
|
||||||
};
|
};
|
||||||
@ -753,33 +754,34 @@ env_sort (const void *a, const void *b)
|
|||||||
struct spenv
|
struct spenv
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
|
size_t namelen;
|
||||||
const char * (cygheap_user::*from_cygheap) ();
|
const char * (cygheap_user::*from_cygheap) ();
|
||||||
char *retrieve (bool, const char * const = NULL, int = 0)
|
char *retrieve (bool, const char * const = NULL)
|
||||||
__attribute__ ((regparm (3)));
|
__attribute__ ((regparm (3)));
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Keep this list in upper case and sorted */
|
/* Keep this list in upper case and sorted */
|
||||||
static NO_COPY spenv spenvs[] =
|
static NO_COPY spenv spenvs[] =
|
||||||
{
|
{
|
||||||
{"HOMEPATH=", &cygheap_user::env_homepath},
|
{NL ("HOMEPATH="), &cygheap_user::env_homepath},
|
||||||
{"HOMEDRIVE=", &cygheap_user::env_homedrive},
|
{NL ("HOMEDRIVE="), &cygheap_user::env_homedrive},
|
||||||
{"LOGONSERVER=", &cygheap_user::env_logsrv},
|
{NL ("LOGONSERVER="), &cygheap_user::env_logsrv},
|
||||||
{"SYSTEMDRIVE=", NULL},
|
{NL ("SYSTEMDRIVE="), NULL},
|
||||||
{"SYSTEMROOT=", NULL},
|
{NL ("SYSTEMROOT="), NULL},
|
||||||
{"USERDOMAIN=", &cygheap_user::env_domain},
|
{NL ("USERDOMAIN="), &cygheap_user::env_domain},
|
||||||
{"USERNAME=", &cygheap_user::env_name},
|
{NL ("USERNAME="), &cygheap_user::env_name},
|
||||||
{"USERPROFILE=", &cygheap_user::env_userprofile},
|
{NL ("USERPROFILE="), &cygheap_user::env_userprofile},
|
||||||
};
|
};
|
||||||
|
|
||||||
char *
|
char *
|
||||||
spenv::retrieve (bool no_envblock, const char *const envname, int len)
|
spenv::retrieve (bool no_envblock, const char *const envname)
|
||||||
{
|
{
|
||||||
if (len && !strncasematch (envname, name, len))
|
if (envname && !strncasematch (envname, name, namelen))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (from_cygheap)
|
if (from_cygheap)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
if (!len)
|
if (!envname)
|
||||||
return NULL; /* No need to force these into the
|
return NULL; /* No need to force these into the
|
||||||
environment */
|
environment */
|
||||||
|
|
||||||
@ -791,21 +793,19 @@ spenv::retrieve (bool no_envblock, const char *const envname, int len)
|
|||||||
method. */
|
method. */
|
||||||
if (!(p = (cygheap->user.*from_cygheap) ()))
|
if (!(p = (cygheap->user.*from_cygheap) ()))
|
||||||
return NULL;
|
return NULL;
|
||||||
int namelen = strlen (name);
|
|
||||||
char *s = (char *) cmalloc (HEAP_1_STR, namelen + strlen (p) + 1);
|
char *s = (char *) cmalloc (HEAP_1_STR, namelen + strlen (p) + 1);
|
||||||
strcpy (s, name);
|
strcpy (s, name);
|
||||||
(void) strcpy (s + namelen, p);
|
(void) strcpy (s + namelen, p);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len)
|
if (envname)
|
||||||
return cstrdup1 (envname);
|
return cstrdup1 (envname);
|
||||||
|
|
||||||
char dum[1];
|
char dum[1];
|
||||||
int vallen = GetEnvironmentVariable (name, dum, 0);
|
int vallen = GetEnvironmentVariable (name, dum, 0);
|
||||||
if (vallen > 0)
|
if (vallen > 0)
|
||||||
{
|
{
|
||||||
int namelen = strlen (name);
|
|
||||||
char *p = (char *) cmalloc (HEAP_1_STR, namelen + ++vallen);
|
char *p = (char *) cmalloc (HEAP_1_STR, namelen + ++vallen);
|
||||||
strcpy (p, name);
|
strcpy (p, name);
|
||||||
if (GetEnvironmentVariable (name, p + namelen, vallen))
|
if (GetEnvironmentVariable (name, p + namelen, vallen))
|
||||||
@ -848,20 +848,19 @@ build_env (const char * const *envp, char *&envblock, int &envc,
|
|||||||
"special" entries, if necessary. */
|
"special" entries, if necessary. */
|
||||||
for (srcp = envp, dstp = newenv; *srcp; srcp++, dstp++)
|
for (srcp = envp, dstp = newenv; *srcp; srcp++, dstp++)
|
||||||
{
|
{
|
||||||
len = strcspn (*srcp, "=") + 1;
|
|
||||||
|
|
||||||
/* Look for entries that require special attention */
|
/* Look for entries that require special attention */
|
||||||
for (unsigned i = 0; i < SPENVS_SIZE; i++)
|
for (unsigned i = 0; i < SPENVS_SIZE; i++)
|
||||||
if (!saw_spenv[i]
|
if (!saw_spenv[i] && (*dstp = spenvs[i].retrieve (no_envblock, *srcp)))
|
||||||
&& (*dstp = spenvs[i].retrieve (no_envblock, *srcp, len)))
|
|
||||||
{
|
{
|
||||||
saw_spenv[i] = 1;
|
saw_spenv[i] = 1;
|
||||||
goto next;
|
goto next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add entry to new environment */
|
||||||
*dstp = cstrdup1 (*srcp);
|
*dstp = cstrdup1 (*srcp);
|
||||||
|
|
||||||
next:
|
next:
|
||||||
|
/* If necessary, calculate rough running total for envblock size */
|
||||||
if (!no_envblock)
|
if (!no_envblock)
|
||||||
tl += strlen (*dstp) + 1;
|
tl += strlen (*dstp) + 1;
|
||||||
}
|
}
|
||||||
@ -879,7 +878,7 @@ build_env (const char * const *envp, char *&envblock, int &envc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
envc = dstp - newenv;
|
envc = dstp - newenv; /* Number of entries in newenv */
|
||||||
*dstp = NULL; /* Terminate */
|
*dstp = NULL; /* Terminate */
|
||||||
|
|
||||||
if (no_envblock)
|
if (no_envblock)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user