[vlc-devel] [PATCH 7/7] darwinvlc: Use FromCFString

Marvin Scholz epirat07 at gmail.com
Mon Oct 8 10:56:03 CEST 2018


---
 bin/darwinvlc.m | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/bin/darwinvlc.m b/bin/darwinvlc.m
index 3ba5c6547b..826d60a5ae 100644
--- a/bin/darwinvlc.m
+++ b/bin/darwinvlc.m
@@ -27,6 +27,9 @@
 #endif
 
 #include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_charset.h>
+
 #include <stdlib.h>
 #include <locale.h>
 #include <signal.h>
@@ -244,21 +247,13 @@ int main(int i_argc, const char *ppsz_argv[])
         language = (CFStringRef)CFPreferencesCopyAppValue(CFSTR("language"),
                                                           kCFPreferencesCurrentApplication);
         if (language) {
-            CFIndex length = CFStringGetLength(language) + 1;
-            if (length > 0) {
-                CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
-                lang = (char *)malloc(maxSize);
-                if(lang) {
-                    CFStringGetCString(language, lang, maxSize - 1, kCFStringEncodingUTF8);
-                    if (strncmp( lang, "auto", 4 )) {
-                        char tmp[11];
-                        snprintf(tmp, 11, "LANG=%s", lang);
-                        putenv(tmp);
-
-                    }
-                }
-                free(lang);
+            lang = FromCFString(language, kCFStringEncodingUTF8);
+            if (strncmp( lang, "auto", 4 )) {
+                char tmp[11];
+                snprintf(tmp, 11, "LANG=%s", lang);
+                putenv(tmp);
             }
+            free(lang);
             CFRelease(language);
         }
     }
-- 
2.19.1



More information about the vlc-devel mailing list