* dcrt0.cc (initial_env): Only use local buffer "buf" if DEBUGGING is
enabled. Replace calls to GetEnvironmentVariable by calls to GetEnvironmentVariableA for clarity. Call GetEnvironmentVariableA with NULL buffer. (cygbench): Ditto, drop local buffer. * environ.cc (getearly): Call GetEnvironmentVariableA. (environ_init): Retrieve unicode environment and convert to current codepage locally. (getwinenveq): Ditto. * exceptions.cc (try_to_debug): Accommodate new sys_mbstowcs calling convention. * fhandler_clipboard.cc (set_clipboard): Call sys_mbstowcs to retrieve required buffer length. * fork.cc (frok::child): Call GetEnvironmentVariableA. * miscfuncs.cc: Accommodate changed arguments in calls to sys_mbstowcs. * sec_auth.cc: Ditto. * strfuncs.cc (sys_wcstombs_alloc): Fix formatting. (sys_mbstowcs): Change arguments to allow specifying a source string length. (sys_mbstowcs_alloc): Ditto. * uinfo.cc (cygheap_user::ontherange): Accommodate changed arguments in calls to sys_mbstowcs. * winsup.h (sys_mbstowcs): Adjust declaration. (sys_mbstowcs_alloc): Ditto.
This commit is contained in:
@@ -64,7 +64,7 @@ sys_wcstombs_alloc (char **tgt_p, int type, const PWCHAR src, int slen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = WideCharToMultiByte (get_cp (), 0, src, slen, NULL, 0,NULL, NULL);
|
||||
ret = WideCharToMultiByte (get_cp (), 0, src, slen, NULL, 0 ,NULL, NULL);
|
||||
if (ret)
|
||||
{
|
||||
size_t tlen = (slen == -1 ? ret : ret + 1);
|
||||
@@ -81,28 +81,35 @@ sys_wcstombs_alloc (char **tgt_p, int type, const PWCHAR src, int slen)
|
||||
}
|
||||
|
||||
int __stdcall
|
||||
sys_mbstowcs (PWCHAR tgt, const char *src, int len)
|
||||
sys_mbstowcs (PWCHAR tgt, int tlen, const char *src, int slen)
|
||||
{
|
||||
int res = MultiByteToWideChar (get_cp (), 0, src, -1, tgt, len);
|
||||
return res;
|
||||
int ret = MultiByteToWideChar (get_cp (), 0, src, slen, tgt, tlen);
|
||||
if (ret && tgt)
|
||||
{
|
||||
ret = (ret < tlen) ? ret : tlen - 1;
|
||||
tgt[ret] = L'\0';
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Same as sys_wcstombs_alloc, just backwards. */
|
||||
int __stdcall
|
||||
sys_mbstowcs_alloc (PWCHAR *tgt_p, int type, const char *src)
|
||||
sys_mbstowcs_alloc (PWCHAR *tgt_p, int type, const char *src, int slen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = MultiByteToWideChar (get_cp (), 0, src, -1, NULL, 0);
|
||||
ret = MultiByteToWideChar (get_cp (), 0, src, slen, NULL, 0);
|
||||
if (ret)
|
||||
{
|
||||
size_t tlen = (slen == -1 ? ret : ret + 1);
|
||||
|
||||
if (type == HEAP_NOTHEAP)
|
||||
*tgt_p = (PWCHAR) calloc (ret, sizeof (WCHAR));
|
||||
*tgt_p = (PWCHAR) calloc (tlen, sizeof (WCHAR));
|
||||
else
|
||||
*tgt_p = (PWCHAR) ccalloc ((cygheap_types) type, ret, sizeof (WCHAR));
|
||||
*tgt_p = (PWCHAR) ccalloc ((cygheap_types) type, tlen, sizeof (WCHAR));
|
||||
if (!*tgt_p)
|
||||
return 0;
|
||||
ret = sys_mbstowcs (*tgt_p, src, ret);
|
||||
ret = sys_mbstowcs (*tgt_p, tlen, src, slen);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user