[vlc-commits] Win32: simplify and fix a warning

Rémi Denis-Courmont git at videolan.org
Thu Mar 22 17:57:11 CET 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Mar 22 18:55:13 2012 +0200| [872d8f2f69ff3f0b88b523a1801324c1f0f4077e] | committer: Rémi Denis-Courmont

Win32: simplify and fix a warning

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=872d8f2f69ff3f0b88b523a1801324c1f0f4077e
---

 src/text/unicode.c |   51 +++++++++++++++++++++------------------------------
 1 files changed, 21 insertions(+), 30 deletions(-)

diff --git a/src/text/unicode.c b/src/text/unicode.c
index cfcf55c..789d0a1 100644
--- a/src/text/unicode.c
+++ b/src/text/unicode.c
@@ -57,7 +57,9 @@ int utf8_vfprintf( FILE *stream, const char *fmt, va_list ap )
     return vfprintf (stream, fmt, ap);
 #else
     char *str;
-    int res;
+    int res = vasprintf (&str, fmt, ap);
+    if (unlikely(res == -1))
+        return -1;
 
 # ifndef UNDER_CE
     /* Writing to the console is a lot of fun on Microsoft Windows.
@@ -67,44 +69,33 @@ int utf8_vfprintf( FILE *stream, const char *fmt, va_list ap )
     int fd = _fileno (stream);
     if (likely(fd != -1) && _isatty (fd))
     {
-        res = vasprintf (&str, fmt, ap);
-        if (unlikely(res == -1))
-            return -1;
-
-        size_t wlen = 2 * (res + 1);
-        wchar_t *wide = malloc (wlen);
+        wchar_t *wide = ToWide (str);
         if (likely(wide != NULL))
         {
-            wlen = MultiByteToWideChar (CP_UTF8, 0, str, res + 1, wide, wlen);
-            if (wlen > 0)
-            {
-                HANDLE h = (HANDLE)(intptr_t)_get_osfhandle (fd);
-                DWORD out;
-
-                WriteConsoleW (h, wide, wlen - 1, &out, NULL);
-            }
-            else
-                res = -1;
+            HANDLE h = (HANDLE)((uintptr_t)_get_osfhandle (fd));
+            DWORD out;
+
+            /* XXX: It is not clear whether WriteConsole() wants the number of
+             * Unicode characters or the size of the wchar_t array. */
+            WriteConsoleW (h, wide, wcslen (wide), &out, NULL);
             free (wide);
         }
         else
             res = -1;
-        free (str);
-        return res;
     }
+    else
 # endif
-
-    res = vasprintf (&str, fmt, ap);
-    if (unlikely(res == -1))
-        return -1;
-
-    char *ansi = ToLocaleDup (str);
+    {
+        char *ansi = ToANSI (str);
+        if (ansi != NULL)
+        {
+            fputs (ansi, stream);
+            free (ansi);
+        }
+        else
+            res = -1;
+    }
     free (str);
-
-    if (ansi == NULL)
-        return -1;
-    fputs (ansi, stream);
-    free (ansi);
     return res;
 #endif
 }



More information about the vlc-commits mailing list