summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/strfuncs.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2008-02-25 18:32:23 +0000
committerCorinna Vinschen <corinna@vinschen.de>2008-02-25 18:32:23 +0000
commit5ab0b5cf529c3f069264b469db4aacbcb95ce760 (patch)
tree0800401dfb684fc09dbafeb0b74319e970bd4fa0 /winsup/cygwin/strfuncs.cc
parentff42f5b1e35d7c605288680b6f7de02d675143b7 (diff)
downloadcygnal-5ab0b5cf529c3f069264b469db4aacbcb95ce760.tar.gz
cygnal-5ab0b5cf529c3f069264b469db4aacbcb95ce760.tar.bz2
cygnal-5ab0b5cf529c3f069264b469db4aacbcb95ce760.zip
* 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.
Diffstat (limited to 'winsup/cygwin/strfuncs.cc')
-rw-r--r--winsup/cygwin/strfuncs.cc25
1 files changed, 16 insertions, 9 deletions
diff --git a/winsup/cygwin/strfuncs.cc b/winsup/cygwin/strfuncs.cc
index e3d7a6c0f..d353fd868 100644
--- a/winsup/cygwin/strfuncs.cc
+++ b/winsup/cygwin/strfuncs.cc
@@ -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;
}