[xbuild] Don't report Imports ignored because of false conditions.
[mono.git] / mono / metadata / locales.c
index 928ce29026652761704311239dfa7c84fa1b7d43..e188ee4ae49a480b08034d7652af0868f61e2c5f 100644 (file)
 #include <mono/metadata/locales.h>
 #include <mono/metadata/culture-info.h>
 #include <mono/metadata/culture-info-tables.h>
-#include <mono/metadata/normalization-tables.h>
 
+#ifndef DISABLE_NORMALIZATION
+#include <mono/metadata/normalization-tables.h>
+#endif
 
 #include <locale.h>
 #if defined(__APPLE__)
@@ -381,11 +383,14 @@ get_posix_locale (void)
 static gchar*
 get_darwin_locale (void)
 {
-       const gchar *darwin_locale = NULL;
-       gchar *cur_locale = NULL;
-       int i;
+       static gchar *darwin_locale = NULL;
        CFLocaleRef locale = NULL;
        CFStringRef locale_cfstr = NULL;
+       CFIndex len;
+       int i;
+
+       if (darwin_locale != NULL)
+               return g_strdup (darwin_locale);
 
        locale = CFLocaleCopyCurrent ();
 
@@ -393,20 +398,24 @@ get_darwin_locale (void)
                locale_cfstr = CFLocaleGetIdentifier (locale);
 
                if (locale_cfstr) {
-                       darwin_locale = CFStringGetCStringPtr (locale_cfstr, kCFStringEncodingMacRoman);
-
-                       cur_locale = g_strdup (darwin_locale);
+                       len = CFStringGetMaximumSizeForEncoding (CFStringGetLength (locale_cfstr), kCFStringEncodingMacRoman) + 1;
+                       darwin_locale = (char *) malloc (len);
+                       if (!CFStringGetCString (locale_cfstr, darwin_locale, len, kCFStringEncodingMacRoman)) {
+                               free (darwin_locale);
+                               CFRelease (locale);
+                               darwin_locale = NULL;
+                               return NULL;
+                       }
 
-                       for (i = 0; i < strlen (cur_locale); i++)
-                               if (cur_locale [i] == '_')
-                                       cur_locale [i] = '-';
+                       for (i = 0; i < strlen (darwin_locale); i++)
+                               if (darwin_locale [i] == '_')
+                                       darwin_locale [i] = '-';
                }
 
-
                CFRelease (locale);
        }
 
-       return cur_locale;
+       return g_strdup (darwin_locale);
 }
 #endif
 
@@ -416,7 +425,7 @@ get_current_locale_name (void)
        gchar *locale;
        gchar *corrected = NULL;
        const gchar *p;
-        gchar *c;
+       gchar *c;
 
 #ifdef HOST_WIN32
        locale = g_win32_getlocale ();
@@ -972,12 +981,16 @@ void load_normalization_resource (guint8 **argProps,
                                  guint8 **argMapIdxToComposite,
                                  guint8 **argCombiningClass)
 {
+#ifdef DISABLE_NORMALIZATION
+       mono_raise_exception (mono_get_exception_not_supported ("This runtime has been compiled without string normalization support."));
+#else
        *argProps = (guint8*)props;
        *argMappedChars = (guint8*) mappedChars;
        *argCharMapIndex = (guint8*) charMapIndex;
        *argHelperIndex = (guint8*) helperIndex;
        *argMapIdxToComposite = (guint8*) mapIdxToComposite;
        *argCombiningClass = (guint8*)combiningClass;
+#endif
 }