aboutsummaryrefslogtreecommitdiff
path: root/binutils/winduni.c
diff options
context:
space:
mode:
authorDanny Smith <dannysmith@users.sourceforge.net>2005-03-24 21:26:21 +0000
committerDanny Smith <dannysmith@users.sourceforge.net>2005-03-24 21:26:21 +0000
commitbcfb5d778fc726dc7b75a402dba027fb4b88f02a (patch)
treed193642c184e75f75a919f79679cc3729bef6511 /binutils/winduni.c
parent510a939ba7af33e52427ac915322c95a74a0fda7 (diff)
downloadgdb-bcfb5d778fc726dc7b75a402dba027fb4b88f02a.zip
gdb-bcfb5d778fc726dc7b75a402dba027fb4b88f02a.tar.gz
gdb-bcfb5d778fc726dc7b75a402dba027fb4b88f02a.tar.bz2
* winduni.c (unicode_from_ascii): Don't declare variables
's' and 'w' if _WIN32. Use MultiByteToWideChar to set the unicode string len.
Diffstat (limited to 'binutils/winduni.c')
-rw-r--r--binutils/winduni.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/binutils/winduni.c b/binutils/winduni.c
index 65bc608..41cfcfc 100644
--- a/binutils/winduni.c
+++ b/binutils/winduni.c
@@ -43,25 +43,32 @@ void
unicode_from_ascii (int *length, unichar **unicode, const char *ascii)
{
int len;
+#ifndef _WIN32
const char *s;
unsigned short *w;
len = strlen (ascii);
-
- if (length != NULL)
- *length = len;
-
*unicode = ((unichar *) res_alloc ((len + 1) * sizeof (unichar)));
-
-#ifdef _WIN32
- /* FIXME: On Windows, we should be using MultiByteToWideChar to set
- the length. */
- MultiByteToWideChar (CP_ACP, 0, ascii, len + 1, *unicode, len + 1);
-#else
for (s = ascii, w = *unicode; *s != '\0'; s++, w++)
*w = *s & 0xff;
*w = 0;
+#else
+ /* We use MultiByteToWideChar rather than strlen to get the unicode
+ string length to allow multibyte "ascii" chars. The value returned
+ by this function includes the trailing '\0'. */
+ len = MultiByteToWideChar (CP_ACP, 0, ascii, -1, NULL, 0);
+ if (len)
+ {
+ *unicode = ((unichar *) res_alloc (len * sizeof (unichar)));
+ MultiByteToWideChar (CP_ACP, 0, ascii, -1, *unicode, len);
+ }
+ /* Discount the trailing '/0'. If MultiByteToWideChar failed,
+ this will set *length to -1. */
+ len--;
#endif
+
+ if (length != NULL)
+ *length = len;
}
/* Print the unicode string UNICODE to the file E. LENGTH is the