summaryrefslogtreecommitdiff
path: root/current/sources/android/support
diff options
context:
space:
mode:
Diffstat (limited to 'current/sources/android/support')
-rw-r--r--current/sources/android/support/Android.mk138
-rw-r--r--current/sources/android/support/NOTICE482
-rw-r--r--current/sources/android/support/include/inttypes.h45
-rw-r--r--current/sources/android/support/include/locale.h43
-rw-r--r--current/sources/android/support/include/math.h81
-rw-r--r--current/sources/android/support/include/stdlib.h48
-rw-r--r--current/sources/android/support/include/uchar.h42
-rw-r--r--current/sources/android/support/include/wchar.h46
-rw-r--r--current/sources/android/support/include/wctype.h40
-rwxr-xr-xcurrent/sources/android/support/regenerate-NOTICE.sh14
-rw-r--r--current/sources/android/support/src/UniquePtr.h137
-rw-r--r--current/sources/android/support/src/locale_support.cpp16
-rw-r--r--current/sources/android/support/src/posix_memalign.cpp20
-rw-r--r--current/sources/android/support/src/support_preinclude.h41
-rw-r--r--current/sources/android/support/src/swprintf.cpp88
-rw-r--r--current/sources/android/support/src/wcstox.cpp127
16 files changed, 1408 insertions, 0 deletions
diff --git a/current/sources/android/support/Android.mk b/current/sources/android/support/Android.mk
new file mode 100644
index 000000000..7cefed18e
--- /dev/null
+++ b/current/sources/android/support/Android.mk
@@ -0,0 +1,138 @@
+LOCAL_PATH := $(call my-dir)
+
+# libandroid_support is only needed on LP32.
+ifeq ($(filter $(NDK_KNOWN_DEVICE_ABI64S),$(TARGET_ARCH_ABI)),)
+
+ifneq ($(LIBCXX_FORCE_REBUILD),true) # Using prebuilt
+
+LIBCXX_LIBS := ../../cxx-stl/llvm-libc++/libs/$(TARGET_ARCH_ABI)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := android_support
+LOCAL_LICENSE_KINDS := SPDX-license-identifier-BSD
+LOCAL_LICENSE_CONDITIONS := notice
+LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE
+LOCAL_SRC_FILES := $(LIBCXX_LIBS)/lib$(LOCAL_MODULE)$(TARGET_LIB_EXTENSION)
+include $(PREBUILT_STATIC_LIBRARY)
+
+else # Building
+
+android_support_cflags := \
+ -D_GNU_SOURCE \
+ -Drestrict=__restrict__ \
+ -ffunction-sections \
+ -fdata-sections \
+ -fvisibility=hidden \
+
+android_support_c_includes := \
+ $(BIONIC_PATH)/libc \
+ $(BIONIC_PATH)/libc/upstream-openbsd/android/include \
+ $(BIONIC_PATH)/libm \
+ $(BIONIC_PATH)/libm/upstream-freebsd/android/include \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src \
+
+android_support_cflags += \
+ -include freebsd-compat.h \
+ -include openbsd-compat.h \
+ -include $(LOCAL_PATH)/src/support_preinclude.h \
+ -D__BIONIC_BUILD_FOR_ANDROID_SUPPORT \
+ -Werror \
+
+android_support_sources := \
+ $(BIONIC_PATH)/libc/bionic/c32rtomb.cpp \
+ $(BIONIC_PATH)/libc/bionic/locale.cpp \
+ $(BIONIC_PATH)/libc/bionic/mbrtoc32.cpp \
+ $(BIONIC_PATH)/libc/bionic/wchar.cpp \
+ $(BIONIC_PATH)/libc/upstream-freebsd/lib/libc/string/wcscat.c \
+ $(BIONIC_PATH)/libc/upstream-freebsd/lib/libc/string/wcschr.c \
+ $(BIONIC_PATH)/libc/upstream-freebsd/lib/libc/string/wcslen.c \
+ $(BIONIC_PATH)/libc/upstream-freebsd/lib/libc/string/wcsncmp.c \
+ $(BIONIC_PATH)/libc/upstream-freebsd/lib/libc/string/wcsncpy.c \
+ $(BIONIC_PATH)/libc/upstream-freebsd/lib/libc/string/wcspbrk.c \
+ $(BIONIC_PATH)/libc/upstream-freebsd/lib/libc/string/wcsrchr.c \
+ $(BIONIC_PATH)/libc/upstream-freebsd/lib/libc/string/wcsspn.c \
+ $(BIONIC_PATH)/libc/upstream-freebsd/lib/libc/string/wcsstr.c \
+ $(BIONIC_PATH)/libc/upstream-freebsd/lib/libc/string/wcstok.c \
+ $(BIONIC_PATH)/libc/upstream-freebsd/lib/libc/string/wmemchr.c \
+ $(BIONIC_PATH)/libc/upstream-freebsd/lib/libc/string/wmemcmp.c \
+ $(BIONIC_PATH)/libc/upstream-freebsd/lib/libc/string/wmemcpy.c \
+ $(BIONIC_PATH)/libc/upstream-freebsd/lib/libc/string/wmemmove.c \
+ $(BIONIC_PATH)/libc/upstream-freebsd/lib/libc/string/wmemset.c \
+ $(BIONIC_PATH)/libc/upstream-openbsd/lib/libc/locale/mbtowc.c \
+ $(BIONIC_PATH)/libc/upstream-openbsd/lib/libc/stdlib/imaxabs.c \
+ $(BIONIC_PATH)/libc/upstream-openbsd/lib/libc/stdlib/imaxdiv.c \
+ $(BIONIC_PATH)/libm/digittoint.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/e_acos.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/e_acosh.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/e_asin.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/e_atan2.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/e_atanh.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/e_cosh.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/e_exp.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/e_hypot.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/e_log.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/e_log10.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/e_log2.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/e_log2f.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/e_logf.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/e_remainder.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/e_sinh.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/e_sqrt.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/k_cos.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/k_exp.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/k_rem_pio2.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/k_sin.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/k_tan.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_asinh.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_atan.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_cbrt.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_cos.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_erf.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_exp2.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_expm1.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_frexp.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_frexpf.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_log1p.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_logb.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_nextafter.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_remquo.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_rint.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_sin.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_tan.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_tanh.c \
+ src/locale_support.cpp \
+ src/posix_memalign.cpp \
+ src/swprintf.cpp \
+ src/wcstox.cpp \
+
+ifeq (x86,$(TARGET_ARCH_ABI))
+# Replaces broken implementations in x86 libm.so
+android_support_sources += \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_scalbln.c \
+ $(BIONIC_PATH)/libm/upstream-freebsd/lib/msun/src/s_scalbn.c \
+
+# fake_long_double.c doesn't define this for x86.
+# TODO: seems like we don't pass .S files to the assembler?
+#android_support_c_includes += $(BIONIC_PATH)/libc/arch-x86/include
+#android_support_sources += $(BIONIC_PATH)/libm/x86/lrint.S
+endif
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := android_support
+LOCAL_LICENSE_KINDS := SPDX-license-identifier-BSD
+LOCAL_LICENSE_CONDITIONS := notice
+LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE
+LOCAL_SRC_FILES := $(android_support_sources)
+LOCAL_C_INCLUDES := $(android_support_c_includes)
+LOCAL_CFLAGS := $(android_support_cflags)
+LOCAL_ARM_NEON := false
+
+LOCAL_CPPFLAGS := \
+ -fvisibility-inlines-hidden \
+ -std=gnu++11 \
+
+include $(BUILD_STATIC_LIBRARY)
+
+endif # Prebuilt/building
+
+endif # LP32
diff --git a/current/sources/android/support/NOTICE b/current/sources/android/support/NOTICE
new file mode 100644
index 000000000..82ed67f0a
--- /dev/null
+++ b/current/sources/android/support/NOTICE
@@ -0,0 +1,482 @@
+====================================================
+Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+
+Developed at SunPro, a Sun Microsystems, Inc. business.
+Permission to use, copy, modify, and distribute this
+software is freely granted, provided that this notice
+is preserved.
+
+-------------------------------------------------------------------
+
+====================================================
+Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+
+Developed at SunPro, a Sun Microsystems, Inc. business.
+Permission to use, copy, modify, and distribute this
+software is freely granted, provided that this notice
+is preserved.
+====================================================
+
+Optimized by Bruce D. Evans.
+
+-------------------------------------------------------------------
+
+====================================================
+Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+
+Developed at SunSoft, a Sun Microsystems, Inc. business.
+Permission to use, copy, modify, and distribute this
+software is freely granted, provided that this notice
+is preserved.
+
+-------------------------------------------------------------------
+
+====================================================
+Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.
+
+Permission to use, copy, modify, and distribute this
+software is freely granted, provided that this notice
+is preserved.
+
+-------------------------------------------------------------------
+
+====================================================
+Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
+
+Permission to use, copy, modify, and distribute this
+software is freely granted, provided that this notice
+is preserved.
+
+-------------------------------------------------------------------
+
+Copyright (C) 2008 The Android Open Source Project
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (C) 2013 The Android Open Source Project
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+-------------------------------------------------------------------
+
+Copyright (C) 2013 The Android Open Source Project
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (C) 2014 The Android Open Source Project
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (C) 2017 The Android Open Source Project
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c) 1989, 1993
+ The Regents of the University of California. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c) 1990, 1993
+ The Regents of the University of California. All rights reserved.
+
+This code is derived from software contributed to Berkeley by
+Chris Torek.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c) 1998 Softweyr LLC. All rights reserved.
+
+strtok_r, from Berkeley strtok
+Oct 13, 1998 by Wes Peters <wes@softweyr.com>
+
+Copyright (c) 1988, 1993
+ The Regents of the University of California. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notices, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notices, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND CONTRIBUTORS
+``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTWEYR LLC, THE
+REGENTS, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c) 2002 Tim J. Robbins
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c) 2002-2004 Tim J. Robbins
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c) 2002-2004 Tim J. Robbins.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c) 2007 David Schultz
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c) 2011 David Schultz <das@FreeBSD.ORG>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
+Copyright (c)1999 Citrus Project,
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+-------------------------------------------------------------------
+
diff --git a/current/sources/android/support/include/inttypes.h b/current/sources/android/support/include/inttypes.h
new file mode 100644
index 000000000..834ab9170
--- /dev/null
+++ b/current/sources/android/support/include/inttypes.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include_next <inttypes.h>
+
+__BEGIN_DECLS
+
+#if __ANDROID_API__ < __ANDROID_API_K__
+intmax_t imaxabs(intmax_t) __attribute_const__;
+imaxdiv_t imaxdiv(intmax_t, intmax_t) __attribute_const__;
+#endif
+
+#if __ANDROID_API__ < __ANDROID_API_L__
+intmax_t wcstoimax(const wchar_t* __restrict, wchar_t** __restrict, int);
+uintmax_t wcstoumax(const wchar_t* __restrict, wchar_t** __restrict, int);
+#endif
+
+__END_DECLS
diff --git a/current/sources/android/support/include/locale.h b/current/sources/android/support/include/locale.h
new file mode 100644
index 000000000..9443f211b
--- /dev/null
+++ b/current/sources/android/support/include/locale.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include_next <locale.h>
+
+__BEGIN_DECLS
+
+#if __ANDROID_API__ < __ANDROID_API_L__
+struct lconv* localeconv(void);
+locale_t duplocale(locale_t);
+void freelocale(locale_t);
+locale_t newlocale(int, const char*, locale_t);
+locale_t uselocale(locale_t);
+#endif
+
+__END_DECLS
diff --git a/current/sources/android/support/include/math.h b/current/sources/android/support/include/math.h
new file mode 100644
index 000000000..8c29c6b47
--- /dev/null
+++ b/current/sources/android/support/include/math.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include_next <math.h>
+
+__BEGIN_DECLS
+
+#if __ANDROID_API__ < __ANDROID_API_J_MR2__
+double log2(double);
+float log2f(float);
+long double log2l(long double);
+long double logbl(long double);
+float tgammaf(float);
+#endif
+
+#if __ANDROID_API__ < __ANDROID_API_L__
+long double acoshl(long double);
+long double acosl(long double);
+long double asinhl(long double);
+long double asinl(long double);
+long double atan2l(long double, long double);
+long double atanhl(long double);
+long double atanl(long double);
+long double cbrtl(long double);
+long double coshl(long double);
+long double cosl(long double);
+long double erfcl(long double);
+long double erfl(long double);
+long double exp2l(long double);
+long double expl(long double);
+long double expm1l(long double);
+long double fmodl(long double, long double);
+long double hypotl(long double, long double);
+long double lgammal(long double);
+long double log10l(long double);
+long double log1pl(long double);
+long double logl(long double);
+long double modfl(long double, long double*);
+long double nearbyintl(long double);
+long double powl(long double, long double);
+long double remainderl(long double, long double);
+long double remquol(long double, long double, int*);
+long double rintl(long double);
+long double sinhl(long double);
+long double sinl(long double);
+long double sqrtl(long double);
+long double tanhl(long double);
+long double tanl(long double);
+long double tgammal(long double);
+long int lrintl(long double);
+long long int llrintl(long double);
+#endif
+
+__END_DECLS
diff --git a/current/sources/android/support/include/stdlib.h b/current/sources/android/support/include/stdlib.h
new file mode 100644
index 000000000..e52e8ce58
--- /dev/null
+++ b/current/sources/android/support/include/stdlib.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include_next <stdlib.h>
+
+__BEGIN_DECLS
+
+#if __ANDROID_API__ < __ANDROID_API_J_MR1__
+int posix_memalign(void** memptr, size_t alignment, size_t size);
+#endif
+
+#if __ANDROID_API__ < __ANDROID_API_L__
+long double strtold_l(const char*, char**, locale_t);
+long long strtoll_l(const char*, char**, int, locale_t);
+unsigned long long strtoull_l(const char*, char**, int, locale_t);
+int mbtowc(wchar_t*, const char*, size_t);
+int at_quick_exit(void (*)(void));
+void quick_exit(int) __noreturn;
+#endif
+
+__END_DECLS
diff --git a/current/sources/android/support/include/uchar.h b/current/sources/android/support/include/uchar.h
new file mode 100644
index 000000000..88e508630
--- /dev/null
+++ b/current/sources/android/support/include/uchar.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include_next <uchar.h>
+
+__BEGIN_DECLS
+
+#if __ANDROID_API__ < __ANDROID_API_L__
+size_t c16rtomb(char* __restrict, char16_t, mbstate_t* __restrict);
+size_t c32rtomb(char* __restrict, char32_t, mbstate_t* __restrict);
+size_t mbrtoc16(char16_t* __restrict, const char* __restrict, size_t, mbstate_t* __restrict);
+size_t mbrtoc32(char32_t* __restrict, const char* __restrict, size_t, mbstate_t* __restrict);
+#endif
+
+__END_DECLS
diff --git a/current/sources/android/support/include/wchar.h b/current/sources/android/support/include/wchar.h
new file mode 100644
index 000000000..edf5bd54d
--- /dev/null
+++ b/current/sources/android/support/include/wchar.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include_next <wchar.h>
+
+__BEGIN_DECLS
+
+#if __ANDROID_API__ < __ANDROID_API_L__
+int vfwscanf(FILE*, const wchar_t*, va_list);
+int vswscanf(const wchar_t*, const wchar_t*, va_list);
+int vwscanf(const wchar_t*, va_list);
+size_t mbsnrtowcs(wchar_t*, const char**, size_t, size_t, mbstate_t*);
+size_t wcsnrtombs(char*, const wchar_t**, size_t, size_t, mbstate_t*);
+float wcstof(const wchar_t*, wchar_t**);
+long long wcstoll(const wchar_t*, wchar_t**, int);
+unsigned long long wcstoull(const wchar_t*, wchar_t**, int);
+#endif
+
+__END_DECLS
diff --git a/current/sources/android/support/include/wctype.h b/current/sources/android/support/include/wctype.h
new file mode 100644
index 000000000..e66c37219
--- /dev/null
+++ b/current/sources/android/support/include/wctype.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include_next <wctype.h>
+
+__BEGIN_DECLS
+
+#if __ANDROID_API__ < __ANDROID_API_L__
+#include <ctype.h>
+static __inline int iswblank(wint_t ch) { return isblank(ch); }
+#endif
+
+__END_DECLS
diff --git a/current/sources/android/support/regenerate-NOTICE.sh b/current/sources/android/support/regenerate-NOTICE.sh
new file mode 100755
index 000000000..0d659c3fb
--- /dev/null
+++ b/current/sources/android/support/regenerate-NOTICE.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+# Change into the libandroid_support directory.
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+cd $DIR
+
+# Pull the notices from the files in libandroid_support itself (via `.`),
+# plus all the bionic files we pull in.
+sed '/$(BIONIC_PATH).*\.c/ { s| *$(BIONIC_PATH)|../../../../bionic/| ; s| *\\$|| ; p } ; d' Android.mk | \
+ xargs ../../../../bionic/libc/tools/generate-NOTICE.py . > NOTICE
+
+# Show the caller what we've done.
+git diff --exit-code HEAD ./NOTICE
+exit $?
diff --git a/current/sources/android/support/src/UniquePtr.h b/current/sources/android/support/src/UniquePtr.h
new file mode 100644
index 000000000..06f14aa1d
--- /dev/null
+++ b/current/sources/android/support/src/UniquePtr.h
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#pragma once
+
+namespace {
+
+#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
+ TypeName(const TypeName&) = delete; \
+ void operator=(const TypeName&) = delete
+
+template <typename T>
+struct DefaultDelete {
+ enum { type_must_be_complete = sizeof(T) };
+ DefaultDelete() {
+ }
+ void operator()(T* p) const {
+ delete p;
+ }
+};
+
+template <typename T>
+struct DefaultDelete<T[]> {
+ enum { type_must_be_complete = sizeof(T) };
+ void operator()(T* p) const {
+ delete[] p;
+ }
+};
+
+template <typename T, typename D = DefaultDelete<T> >
+class UniquePtr {
+ public:
+ explicit UniquePtr(T* ptr = NULL) : mPtr(ptr) {
+ }
+
+ ~UniquePtr() {
+ reset();
+ }
+
+ T& operator*() const {
+ return *mPtr;
+ }
+ T* operator->() const {
+ return mPtr;
+ }
+ T* get() const {
+ return mPtr;
+ }
+
+ T* release() __attribute__((warn_unused_result)) {
+ T* result = mPtr;
+ mPtr = NULL;
+ return result;
+ }
+
+ void reset(T* ptr = NULL) {
+ if (ptr != mPtr) {
+ D()(mPtr);
+ mPtr = ptr;
+ }
+ }
+
+ private:
+ T* mPtr;
+
+ template <typename T2>
+ bool operator==(const UniquePtr<T2>& p) const;
+ template <typename T2>
+ bool operator!=(const UniquePtr<T2>& p) const;
+
+ DISALLOW_COPY_AND_ASSIGN(UniquePtr);
+};
+
+// Partial specialization for array types. Like std::unique_ptr, this removes
+// operator* and operator-> but adds operator[].
+template <typename T, typename D>
+class UniquePtr<T[], D> {
+ public:
+ explicit UniquePtr(T* ptr = NULL) : mPtr(ptr) {
+ }
+
+ ~UniquePtr() {
+ reset();
+ }
+
+ T& operator[](size_t i) const {
+ return mPtr[i];
+ }
+ T* get() const {
+ return mPtr;
+ }
+
+ T* release() __attribute__((warn_unused_result)) {
+ T* result = mPtr;
+ mPtr = NULL;
+ return result;
+ }
+
+ void reset(T* ptr = NULL) {
+ if (ptr != mPtr) {
+ D()(mPtr);
+ mPtr = ptr;
+ }
+ }
+
+ private:
+ T* mPtr;
+
+ DISALLOW_COPY_AND_ASSIGN(UniquePtr);
+};
+
+} // anonymous namespace
diff --git a/current/sources/android/support/src/locale_support.cpp b/current/sources/android/support/src/locale_support.cpp
new file mode 100644
index 000000000..a730fc6b0
--- /dev/null
+++ b/current/sources/android/support/src/locale_support.cpp
@@ -0,0 +1,16 @@
+#include <stdlib.h>
+#include <xlocale.h>
+
+long long strtoll_l(const char* nptr, char** endptr, int base, locale_t loc) {
+ return strtoll(nptr, endptr, base);
+}
+
+unsigned long long strtoull_l(const char* nptr, char** endptr, int base,
+ locale_t loc) {
+ return strtoull(nptr, endptr, base);
+}
+
+long double strtold_l(const char* nptr, char** endptr,
+ locale_t __unused locale) {
+ return strtold(nptr, endptr);
+}
diff --git a/current/sources/android/support/src/posix_memalign.cpp b/current/sources/android/support/src/posix_memalign.cpp
new file mode 100644
index 000000000..cf7abbbf5
--- /dev/null
+++ b/current/sources/android/support/src/posix_memalign.cpp
@@ -0,0 +1,20 @@
+#include <errno.h>
+#include <malloc.h>
+#include <stdlib.h>
+
+int posix_memalign(void** memptr, size_t alignment, size_t size) {
+ if ((alignment & (alignment - 1)) != 0 || alignment == 0) {
+ return EINVAL;
+ }
+
+ if (alignment % sizeof(void*) != 0) {
+ return EINVAL;
+ }
+
+ *memptr = memalign(alignment, size);
+ if (*memptr == NULL) {
+ return errno;
+ }
+
+ return 0;
+}
diff --git a/current/sources/android/support/src/support_preinclude.h b/current/sources/android/support/src/support_preinclude.h
new file mode 100644
index 000000000..bf090b0d2
--- /dev/null
+++ b/current/sources/android/support/src/support_preinclude.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#pragma once
+
+// Declare cimag and creal for use by __ldexp_cexp. libandroid_runtime doesn't
+// really need __ldexp_cexp, but it does need __ldexp_exp, and both functions
+// are defined in the same C file. complex.h doesn't declare cimag/creal when
+// building libandroid_support, because the functions are only available
+// starting with M, and libandroid_support is compiled for the oldest supported
+// NDK API.
+//
+// The two functions are trivial (and have __builtin_{cimag,creal}
+// equivalents). Clang inlines calls to these functions even with -O0.
+double cimag(double _Complex z);
+double creal(double _Complex z);
diff --git a/current/sources/android/support/src/swprintf.cpp b/current/sources/android/support/src/swprintf.cpp
new file mode 100644
index 000000000..01cfe5da2
--- /dev/null
+++ b/current/sources/android/support/src/swprintf.cpp
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <wchar.h>
+
+#include "UniquePtr.h"
+
+namespace {
+const size_t MBS_FAILURE = static_cast<size_t>(-1);
+}
+
+int swprintf(wchar_t* wcs, size_t maxlen, const wchar_t* format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ int result = vswprintf(wcs, maxlen, format, ap);
+ va_end(ap);
+ return result;
+}
+
+int vswprintf(wchar_t* wcs, size_t maxlen, const wchar_t* fmt, va_list ap) {
+ mbstate_t mbstate;
+ memset(&mbstate, 0, sizeof(mbstate));
+
+ // At most, each wide character (UTF-32) can be expanded to four narrow
+ // characters (UTF-8).
+ const size_t max_mb_len = maxlen * 4;
+ const size_t mb_fmt_len = wcslen(fmt) * 4 + 1;
+ UniquePtr<char[]> mbfmt(new char[mb_fmt_len]);
+ if (wcsrtombs(mbfmt.get(), &fmt, mb_fmt_len, &mbstate) == MBS_FAILURE) {
+ return -1;
+ }
+
+ UniquePtr<char[]> mbs(new char[max_mb_len]);
+ int nprinted = vsnprintf(mbs.get(), max_mb_len, mbfmt.get(), ap);
+ if (nprinted == -1) {
+ return -1;
+ }
+
+ const char* mbsp = mbs.get();
+ if (mbsrtowcs(wcs, &mbsp, maxlen, &mbstate) == MBS_FAILURE) {
+ return -1;
+ }
+
+ // Can't use return value from vsnprintf because that number is in narrow
+ // characters, not wide characters.
+ int result = wcslen(wcs);
+
+ // swprintf differs from snprintf in that it returns -1 if the output was
+ // truncated.
+ //
+ // Truncation can occur in two places:
+ // 1) vsnprintf truncated, in which case the return value is greater than the
+ // length we passed.
+ // 2) Since the char buffer we pass to vsnprintf might be oversized, that
+ // might not truncate while mbsrtowcs will. In this case, mbsp will point
+ // to the next unconverted character instead of nullptr.
+ if (nprinted >= max_mb_len || mbsp != nullptr) {
+ return -1;
+ }
+
+ return result;
+}
diff --git a/current/sources/android/support/src/wcstox.cpp b/current/sources/android/support/src/wcstox.cpp
new file mode 100644
index 000000000..c799b3f57
--- /dev/null
+++ b/current/sources/android/support/src/wcstox.cpp
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+#include <stdlib.h>
+#include <wchar.h>
+
+#include "UniquePtr.h"
+
+namespace {
+constexpr size_t MBS_FAILURE = static_cast<size_t>(-1);
+}
+
+template <typename T>
+static T wcstox(T (*func)(const char*, char**, int), const wchar_t* wcs,
+ wchar_t** wcs_end, int base) {
+ mbstate_t mbstate;
+ memset(&mbstate, 0, sizeof(mbstate));
+
+ if (wcs_end != nullptr) {
+ *wcs_end = const_cast<wchar_t*>(wcs);
+ }
+
+ const size_t max_mb_len = wcslen(wcs) * 4 + 1;
+ UniquePtr<char[]> mbs(new char[max_mb_len]);
+ const wchar_t* s = wcs;
+ if (wcsrtombs(mbs.get(), &s, max_mb_len, &mbstate) == MBS_FAILURE) {
+ return static_cast<T>(0);
+ }
+
+ char* mbs_end;
+ T value = func(mbs.get(), &mbs_end, base);
+ if (wcs_end == nullptr) {
+ // If the user passed nullptr for the end pointer, we don't need to compute
+ // it and can return early.
+ return value;
+ }
+
+ // strto* can set ERANGE or EINVAL. Preserve the value of errno in case any of
+ // the things we're about to do to comput the end pointer don't clobber it.
+ int preserved_errno = errno;
+
+ // wcs_end needs to point to the character after the one converted. We don't
+ // know how many wide characters were converted, but we can figure that out by
+ // converting the multibyte string between mbs and mbs_end back to a wide
+ // character string.
+ size_t converted_len = mbs_end - mbs.get();
+ UniquePtr<char[]> converted_mbs(new char[converted_len + 1]);
+ strncpy(converted_mbs.get(), mbs.get(), converted_len);
+ converted_mbs[converted_len] = '\0';
+
+ const char* mbsp = converted_mbs.get();
+ size_t converted_wlen = mbsrtowcs(nullptr, &mbsp, 0, &mbstate);
+ if (converted_wlen == MBS_FAILURE) {
+ // This should be impossible.
+ abort();
+ }
+
+ *wcs_end = const_cast<wchar_t*>(wcs) + converted_wlen;
+ errno = preserved_errno;
+ return value;
+}
+
+static float strtof_wrapper(const char* s, char** p, int) {
+ return strtof(s, p);
+}
+
+float wcstof(const wchar_t* s, wchar_t** p) {
+ return wcstox(strtof_wrapper, s, p, 0);
+}
+
+static double strtod_wrapper(const char* s, char** p, int) {
+ return strtod(s, p);
+}
+
+double wcstod(const wchar_t *restrict s, wchar_t **restrict p) {
+ return wcstox(strtod_wrapper, s, p, 0);
+}
+
+long wcstol(const wchar_t *restrict s, wchar_t **restrict p, int base) {
+ return wcstox(strtol, s, p, base);
+}
+
+unsigned long wcstoul(const wchar_t *restrict s, wchar_t **restrict p, int base) {
+ return wcstox(strtoul, s, p, base);
+}
+
+long long wcstoll(const wchar_t *restrict s, wchar_t **restrict p, int base) {
+ return wcstox(strtoll, s, p, base);
+}
+
+unsigned long long wcstoull(const wchar_t *restrict s, wchar_t **restrict p, int base) {
+ return wcstox(strtoull, s, p, base);
+}
+
+intmax_t wcstoimax(const wchar_t *restrict s, wchar_t **restrict p, int base) {
+ return wcstox(strtoimax, s, p, base);
+}
+
+uintmax_t wcstoumax(const wchar_t *restrict s, wchar_t **restrict p, int base) {
+ return wcstox(strtoumax, s, p, base);
+}