libc++: Add missing license lines + fix wchar support.

This patch adds missing license disclaimer to the new libc++ files.
It also fixes a few bugs in the wchar support code.

Note to self: write unit test suite for all these functions.

Change-Id: I267fc7ddfaaba94ab343faefc87dc4fabf0a8413
diff --git a/sources/cxx-stl/llvm-libc++/android/llvm-libc++/Android.mk b/sources/cxx-stl/llvm-libc++/android/llvm-libc++/Android.mk
index 4bca4f6..0a178bc 100644
--- a/sources/cxx-stl/llvm-libc++/android/llvm-libc++/Android.mk
+++ b/sources/cxx-stl/llvm-libc++/android/llvm-libc++/Android.mk
@@ -1,3 +1,6 @@
+# This file is dual licensed under the MIT and the University of Illinois Open
+# Source Licenses. See LICENSE.TXT for details.
+
 LOCAL_PATH := $(call my-dir)/../..
 
 llvm_libc++_includes := $(LOCAL_PATH)/include $(LOCAL_PATH)/include/support/android
diff --git a/sources/cxx-stl/llvm-libc++/android/test/jni/Android.mk b/sources/cxx-stl/llvm-libc++/android/test/jni/Android.mk
index 4305c97..345dfb6 100644
--- a/sources/cxx-stl/llvm-libc++/android/test/jni/Android.mk
+++ b/sources/cxx-stl/llvm-libc++/android/test/jni/Android.mk
@@ -1,3 +1,6 @@
+# This file is dual licensed under the MIT and the University of Illinois Open
+# Source Licenses. See LICENSE.TXT for details.
+
 LOCAL_PATH := $(call my-dir)
 
 include $(CLEAR_VARS)
diff --git a/sources/cxx-stl/llvm-libc++/android/test/jni/Application.mk b/sources/cxx-stl/llvm-libc++/android/test/jni/Application.mk
index a252a72..0da80f3 100644
--- a/sources/cxx-stl/llvm-libc++/android/test/jni/Application.mk
+++ b/sources/cxx-stl/llvm-libc++/android/test/jni/Application.mk
@@ -1 +1,4 @@
+# This file is dual licensed under the MIT and the University of Illinois Open
+# Source Licenses. See LICENSE.TXT for details.
+
 APP_ABI := all
diff --git a/sources/cxx-stl/llvm-libc++/android/test/jni/test_1.cc b/sources/cxx-stl/llvm-libc++/android/test/jni/test_1.cc
index 376997f..963d8a1 100644
--- a/sources/cxx-stl/llvm-libc++/android/test/jni/test_1.cc
+++ b/sources/cxx-stl/llvm-libc++/android/test/jni/test_1.cc
@@ -1,3 +1,13 @@
+// -*- C++ -*-
+//===-------------------- support/android/wchar_support.c ------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
 #include <iostream>
 
 int main(void) {
diff --git a/sources/cxx-stl/llvm-libc++/include/support/android/ctype.h b/sources/cxx-stl/llvm-libc++/include/support/android/ctype.h
index 847a340..5aaca52 100644
--- a/sources/cxx-stl/llvm-libc++/include/support/android/ctype.h
+++ b/sources/cxx-stl/llvm-libc++/include/support/android/ctype.h
@@ -1,3 +1,13 @@
+// -*- C++ -*-
+//===-------------------- support/android/wchar_support.c ------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
 #ifndef LLVM_LIBCXX_SUPPORT_ANDROID_CTYPE_H
 #define LLVM_LIBCXX_SUPPORT_ANDROID_CTYPE_H
 
diff --git a/sources/cxx-stl/llvm-libc++/include/support/android/langinfo.h b/sources/cxx-stl/llvm-libc++/include/support/android/langinfo.h
index c3a6ebb..b8e1cf1 100644
--- a/sources/cxx-stl/llvm-libc++/include/support/android/langinfo.h
+++ b/sources/cxx-stl/llvm-libc++/include/support/android/langinfo.h
@@ -1,3 +1,13 @@
+// -*- C++ -*-
+//===-------------------- support/android/wchar_support.c ------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
 #ifndef LLVM_LIBCXX_SUPPORT_ANDROID_LANGINFO_H
 #define LLVM_LIBCXX_SUPPORT_ANDROID_LANGINFO_H
 
diff --git a/sources/cxx-stl/llvm-libc++/include/support/android/locale.h b/sources/cxx-stl/llvm-libc++/include/support/android/locale.h
index 2f98dc5..01c834f 100644
--- a/sources/cxx-stl/llvm-libc++/include/support/android/locale.h
+++ b/sources/cxx-stl/llvm-libc++/include/support/android/locale.h
@@ -1,3 +1,13 @@
+// -*- C++ -*-
+//===-------------------- support/android/wchar_support.c ------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
 #ifndef LLVM_LIBCXX_SUPPORT_ANDROID_LOCALE_H
 #define LLVM_LIBCXX_SUPPORT_ANDROID_LOCALE_H
 
diff --git a/sources/cxx-stl/llvm-libc++/include/support/android/math.h b/sources/cxx-stl/llvm-libc++/include/support/android/math.h
index 1890945..d494aec 100644
--- a/sources/cxx-stl/llvm-libc++/include/support/android/math.h
+++ b/sources/cxx-stl/llvm-libc++/include/support/android/math.h
@@ -1,3 +1,13 @@
+// -*- C++ -*-
+//===-------------------- support/android/wchar_support.c ------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
 #ifndef LLVM_LIBCXX_SUPPORT_ANDROID_MATH_H
 #define LLVM_LIBCXX_SUPPORT_ANDROID_MATH_H
 
diff --git a/sources/cxx-stl/llvm-libc++/include/support/android/nl_types.h b/sources/cxx-stl/llvm-libc++/include/support/android/nl_types.h
index 3346da8..d43efce 100644
--- a/sources/cxx-stl/llvm-libc++/include/support/android/nl_types.h
+++ b/sources/cxx-stl/llvm-libc++/include/support/android/nl_types.h
@@ -1,3 +1,13 @@
+// -*- C++ -*-
+//===-------------------- support/android/wchar_support.c ------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
 #ifndef LLVM_LIBCXX_SUPPORT_ANDROID_NL_TYPES_H
 #define LLVM_LIBCXX_SUPPORT_ANDROID_NL_TYPES_H
 
diff --git a/sources/cxx-stl/llvm-libc++/include/support/android/stdio.h b/sources/cxx-stl/llvm-libc++/include/support/android/stdio.h
index 8d0b3da..5e6dc55 100644
--- a/sources/cxx-stl/llvm-libc++/include/support/android/stdio.h
+++ b/sources/cxx-stl/llvm-libc++/include/support/android/stdio.h
@@ -1,3 +1,13 @@
+// -*- C++ -*-
+//===-------------------- support/android/wchar_support.c ------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
 #ifndef LLVM_LIBCXX_SUPPORT_ANDROID_STDIO_H
 #define LLVM_LIBCXX_SUPPORT_ANDROID_STDIO_H
 
diff --git a/sources/cxx-stl/llvm-libc++/include/support/android/stdlib.h b/sources/cxx-stl/llvm-libc++/include/support/android/stdlib.h
index 3ce85dd..bafbfe5 100644
--- a/sources/cxx-stl/llvm-libc++/include/support/android/stdlib.h
+++ b/sources/cxx-stl/llvm-libc++/include/support/android/stdlib.h
@@ -1,3 +1,13 @@
+// -*- C++ -*-
+//===-------------------- support/android/wchar_support.c ------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
 #ifndef LLVM_LIBCXX_SUPPORT_ANDROID_STDLIB_H
 #define LLVM_LIBCXX_SUPPORT_ANDROID_STDLIB_H
 
diff --git a/sources/cxx-stl/llvm-libc++/include/support/android/string.h b/sources/cxx-stl/llvm-libc++/include/support/android/string.h
index b78b494..1c7e27a 100644
--- a/sources/cxx-stl/llvm-libc++/include/support/android/string.h
+++ b/sources/cxx-stl/llvm-libc++/include/support/android/string.h
@@ -1,3 +1,13 @@
+// -*- C++ -*-
+//===-------------------- support/android/wchar_support.c ------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
 #ifndef LLVM_LIBCXX_SUPPORT_ANDROID_STRING_H
 #define LLVM_LIBCXX_SUPPORT_ANDROID_STRING_H
 
diff --git a/sources/cxx-stl/llvm-libc++/include/support/android/time.h b/sources/cxx-stl/llvm-libc++/include/support/android/time.h
index 3706af8..ac70b3f 100644
--- a/sources/cxx-stl/llvm-libc++/include/support/android/time.h
+++ b/sources/cxx-stl/llvm-libc++/include/support/android/time.h
@@ -1,3 +1,13 @@
+// -*- C++ -*-
+//===-------------------- support/android/wchar_support.c ------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
 #ifndef LLVM_LIBCXX_SUPPORT_ANDROID_TIME_H
 #define LLVM_LIBCXX_SUPPORT_ANDROID_TIME_H
 
diff --git a/sources/cxx-stl/llvm-libc++/include/support/android/wchar.h b/sources/cxx-stl/llvm-libc++/include/support/android/wchar.h
index f80f592..2c6b745 100644
--- a/sources/cxx-stl/llvm-libc++/include/support/android/wchar.h
+++ b/sources/cxx-stl/llvm-libc++/include/support/android/wchar.h
@@ -1,3 +1,13 @@
+// -*- C++ -*-
+//===-------------------- support/android/wchar_support.c ------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
 #ifndef LLVM_LIBCXX_SUPPORT_ANDROID_WCHAR_H
 #define LLVM_LIBCXX_SUPPORT_ANDROID_WCHAR_H
 
diff --git a/sources/cxx-stl/llvm-libc++/include/support/android/wctype.h b/sources/cxx-stl/llvm-libc++/include/support/android/wctype.h
index 4291f8a..e4bd689 100644
--- a/sources/cxx-stl/llvm-libc++/include/support/android/wctype.h
+++ b/sources/cxx-stl/llvm-libc++/include/support/android/wctype.h
@@ -1,3 +1,13 @@
+// -*- C++ -*-
+//===-------------------- support/android/wchar_support.c ------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
 #ifndef LLVM_LIBCXX_SUPPORT_ANDROID_WCTYPES_H
 #define LLVM_LIBCXX_SUPPORT_ANDROID_WCTYPES_H
 
diff --git a/sources/cxx-stl/llvm-libc++/include/support/android/xlocale.h b/sources/cxx-stl/llvm-libc++/include/support/android/xlocale.h
index c391c57..0e0db14 100644
--- a/sources/cxx-stl/llvm-libc++/include/support/android/xlocale.h
+++ b/sources/cxx-stl/llvm-libc++/include/support/android/xlocale.h
@@ -1,3 +1,13 @@
+// -*- C++ -*-
+//===-------------------- support/android/wchar_support.c ------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
 #ifndef LLVM_LIBCXX_SUPPORT_ANDROID_XLOCALE_H
 #define LLVM_LIBCXX_SUPPORT_ANDROID_XLOCALE_H
 
@@ -5,7 +15,7 @@
 extern "C" {
 #endif
 
-typedef struct locale_struct*  locale_t;
+typedef struct locale_struct* locale_t;
 
 struct locale_struct {
     void* dummy;
diff --git a/sources/cxx-stl/llvm-libc++/src/support/android/wchar_support.c b/sources/cxx-stl/llvm-libc++/src/support/android/wchar_support.c
index 6987bcd..5227382 100644
--- a/sources/cxx-stl/llvm-libc++/src/support/android/wchar_support.c
+++ b/sources/cxx-stl/llvm-libc++/src/support/android/wchar_support.c
@@ -17,6 +17,7 @@
     while (*delim) {
         if (wc == *delim)
             return 1;
+        delim++;
     }
     return 0;
 }
@@ -30,7 +31,7 @@
             break;
         n++;
     }
-    return to;
+    return to + n;
 }
 
 wchar_t *wcpncpy(wchar_t *dst, const wchar_t *src, size_t n) {
@@ -72,6 +73,7 @@
         s1[n+i] = wc;
         if (wc == L'\0')
             break;
+        i++;
     }
     return s1;
 }
@@ -82,9 +84,12 @@
         return 0;
 
     // Skip dst characters.
-    size_t n;
-    for (n = 0; n < siz && dst[n] != L'\0'; ++n)
-        ;
+    size_t n = 0;
+    while (n < siz && dst[n] != L'\0')
+      n++;
+
+    if (n == siz)
+      return n + wcslen(src);
 
     // Copy as much source characters as they fit into siz-1 bytes.
     size_t i;