(CYGWIN_VERSION_DLL_MAKE_COMBINED (user_data->api_major, user_data->api_minor) \
<= CYGWIN_VERSION_DLL_MALLOC_ENV)
+#define NL(x) x, (sizeof (x) - 1)
/* List of names which are converted from dos to unix
on the way in and back again on the way out.
static int return_MAX_PATH (const char *) {return MAX_PATH;}
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_win32_to_posix_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},
- {"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},
- {"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},
- {"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},
- {"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},
{NULL, 0, NULL, NULL, NULL, NULL, 0, 0}
};
struct spenv
{
const char *name;
+ size_t namelen;
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)));
};
/* Keep this list in upper case and sorted */
static NO_COPY spenv spenvs[] =
{
- {"HOMEPATH=", &cygheap_user::env_homepath},
- {"HOMEDRIVE=", &cygheap_user::env_homedrive},
- {"LOGONSERVER=", &cygheap_user::env_logsrv},
- {"SYSTEMDRIVE=", NULL},
- {"SYSTEMROOT=", NULL},
- {"USERDOMAIN=", &cygheap_user::env_domain},
- {"USERNAME=", &cygheap_user::env_name},
- {"USERPROFILE=", &cygheap_user::env_userprofile},
+ {NL ("HOMEPATH="), &cygheap_user::env_homepath},
+ {NL ("HOMEDRIVE="), &cygheap_user::env_homedrive},
+ {NL ("LOGONSERVER="), &cygheap_user::env_logsrv},
+ {NL ("SYSTEMDRIVE="), NULL},
+ {NL ("SYSTEMROOT="), NULL},
+ {NL ("USERDOMAIN="), &cygheap_user::env_domain},
+ {NL ("USERNAME="), &cygheap_user::env_name},
+ {NL ("USERPROFILE="), &cygheap_user::env_userprofile},
};
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;
if (from_cygheap)
{
const char *p;
- if (!len)
+ if (!envname)
return NULL; /* No need to force these into the
environment */
method. */
if (!(p = (cygheap->user.*from_cygheap) ()))
return NULL;
- int namelen = strlen (name);
char *s = (char *) cmalloc (HEAP_1_STR, namelen + strlen (p) + 1);
strcpy (s, name);
(void) strcpy (s + namelen, p);
return s;
}
- if (len)
+ if (envname)
return cstrdup1 (envname);
char dum[1];
int vallen = GetEnvironmentVariable (name, dum, 0);
if (vallen > 0)
{
- int namelen = strlen (name);
char *p = (char *) cmalloc (HEAP_1_STR, namelen + ++vallen);
strcpy (p, name);
if (GetEnvironmentVariable (name, p + namelen, vallen))
"special" entries, if necessary. */
for (srcp = envp, dstp = newenv; *srcp; srcp++, dstp++)
{
- len = strcspn (*srcp, "=") + 1;
-
/* Look for entries that require special attention */
for (unsigned i = 0; i < SPENVS_SIZE; i++)
- if (!saw_spenv[i]
- && (*dstp = spenvs[i].retrieve (no_envblock, *srcp, len)))
+ if (!saw_spenv[i] && (*dstp = spenvs[i].retrieve (no_envblock, *srcp)))
{
saw_spenv[i] = 1;
goto next;
}
+ /* Add entry to new environment */
*dstp = cstrdup1 (*srcp);
next:
+ /* If necessary, calculate rough running total for envblock size */
if (!no_envblock)
tl += strlen (*dstp) + 1;
}
}
}
- envc = dstp - newenv;
+ envc = dstp - newenv; /* Number of entries in newenv */
*dstp = NULL; /* Terminate */
if (no_envblock)