Fixes for FreeBSD, including some fairly obvious copy-and-paste errors.

libc++ now mostly works on FreeBSD with libcxxrt and this patch applied to the base system:

http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20110920/e666632c/xlocale-0001.obj

Summary of tests on FreeBSD:


****************************************************
Results for /root/libcxx/test:
using FreeBSD clang version 3.0 (trunk 135360) 20110717
Target: x86_64-unknown-freebsd9.0
Thread model: posix
with -std=c++0x -stdlib=libc++ -I/root/libcxx/include -L/root/libcxx/build/lib
----------------------------------------------------
sections without tests   : 1
sections with failures   : 48
sections without failures: 1015
                       +   ----
total number of sections : 1064
----------------------------------------------------
number of tests failed   : 145
number of tests passed   : 4179
                       +   ----
total number of tests    : 4324
****************************************************

(Many due to this clang version not supporting C++ atomics)

More fixes to follow...



git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@140245 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/src/locale.cpp b/src/locale.cpp
index a9fccec..8f1e4e1 100644
--- a/src/locale.cpp
+++ b/src/locale.cpp
@@ -733,7 +733,7 @@
 wchar_t
 ctype<wchar_t>::do_toupper(char_type c) const
 {
-#ifndef _LIBCPP_STABLE_APPLE_ABI
+#if !(defined(_LIBCPP_STABLE_APPLE_ABI) || defined(__FreeBSD__))
     return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
 #else
     return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
@@ -744,7 +744,7 @@
 ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const
 {
     for (; low != high; ++low)
-#ifndef _LIBCPP_STABLE_APPLE_ABI
+#if !(defined(_LIBCPP_STABLE_APPLE_ABI) || defined(__FreeBSD__))
         *low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low]
                              : *low;
 #else
@@ -908,11 +908,12 @@
 const ctype<char>::mask*
 ctype<char>::classic_table()  _NOEXCEPT
 {
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(__FreeBSD__)
     return _DefaultRuneLocale.__runetype;
 #elif defined(__GLIBC__)
     return __cloc()->__ctype_b;
-// This is assumed to be safe.
+// This is assumed to be safe, which is a nonsense assumption because we're
+// going to end up dereferencing it later...
 #else
     return NULL;
 #endif
@@ -922,7 +923,7 @@
 const int*
 ctype<char>::__classic_lower_table() _NOEXCEPT
 {
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(__FreeBSD__)
     return _DefaultRuneLocale.__maplower;
 #elif defined(__GLIBC__)
     return __cloc()->__ctype_tolower;
@@ -934,7 +935,7 @@
 const int*
 ctype<char>::__classic_upper_table() _NOEXCEPT
 {
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(__FreeBSD__)
     return _DefaultRuneLocale.__mapupper;
 #elif defined(__GLIBC__)
     return __cloc()->__ctype_toupper;
@@ -1036,6 +1037,7 @@
 #ifdef _LIBCPP_WCTYPE_IS_MASK
     return static_cast<bool>(iswctype_l(c, m, __l));
 #else
+	// FIXME: This is broken for things that test more than one flag.
     if (m & space && !iswspace_l(c, __l)) return false;
     if (m & print && !iswprint_l(c, __l)) return false;
     if (m & cntrl && !iswcntrl_l(c, __l)) return false;