diff --git a/libc/Android.mk b/libc/Android.mk index 916b63c12..893738ae0 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -206,16 +206,10 @@ libc_bionic_src_files := \ bionic/socket.cpp \ bionic/stat.cpp \ bionic/statvfs.cpp \ - bionic/strcoll_l.cpp \ bionic/strerror.cpp \ bionic/strerror_r.cpp \ - bionic/strftime_l.cpp \ bionic/strsignal.cpp \ bionic/strtold.cpp \ - bionic/strtold_l.cpp \ - bionic/strtoll_l.cpp \ - bionic/strtoull_l.cpp \ - bionic/strxfrm_l.cpp \ bionic/stubs.cpp \ bionic/symlink.cpp \ bionic/sysconf.cpp \ diff --git a/libc/bionic/locale.cpp b/libc/bionic/locale.cpp index b4a3472d7..681e03836 100644 --- a/libc/bionic/locale.cpp +++ b/libc/bionic/locale.cpp @@ -29,6 +29,10 @@ #include #include #include +#include +#include +#include +#include #include "private/bionic_macros.h" @@ -171,3 +175,47 @@ locale_t uselocale(locale_t new_locale) { return old_locale; } + +int strcasecmp_l(const char* s1, const char* s2, locale_t) { + return strcasecmp(s1, s2); +} + +int strcoll_l(const char* s1, const char* s2, locale_t) { + return strcoll(s1, s2); +} + +char* strerror_l(int error, locale_t) { + return strerror(error); +} + +size_t strftime_l(char* s, size_t max, const char* format, const struct tm* tm, locale_t) { + return strftime(s, max, format, tm); +} + +int strncasecmp_l(const char* s1, const char* s2, size_t n, locale_t) { + return strncasecmp(s1, s2, n); +} + +long double strtold_l(const char* s, char** end_ptr, locale_t) { + return strtold(s, end_ptr); +} + +long long strtoll_l(const char* s, char** end_ptr, int base, locale_t) { + return strtoll(s, end_ptr, base); +} + +unsigned long long strtoull_l(const char* s, char** end_ptr, int base, locale_t) { + return strtoull(s, end_ptr, base); +} + +size_t strxfrm_l(char* dst, const char* src, size_t n, locale_t) { + return strxfrm(dst, src, n); +} + +int wcscasecmp_l(const wchar_t* ws1, const wchar_t* ws2, locale_t) { + return wcscasecmp(ws1, ws2); +} + +int wcsncasecmp_l(const wchar_t* ws1, const wchar_t* ws2, size_t n, locale_t) { + return wcsncasecmp(ws1, ws2, n); +} diff --git a/libc/bionic/strcoll_l.cpp b/libc/bionic/strcoll_l.cpp deleted file mode 100644 index 7d7c28bef..000000000 --- a/libc/bionic/strcoll_l.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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. - */ - -#include - -int strcoll_l(const char *s1, const char *s2, locale_t) { - return strcoll(s1, s2); -} diff --git a/libc/bionic/strftime_l.cpp b/libc/bionic/strftime_l.cpp deleted file mode 100644 index fb01da5f2..000000000 --- a/libc/bionic/strftime_l.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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. - */ - -#include - -size_t strftime_l(char *s, size_t max, const char *format, const struct tm *tm, - locale_t) { - return strftime(s, max, format, tm); -} diff --git a/libc/bionic/strtold_l.cpp b/libc/bionic/strtold_l.cpp deleted file mode 100644 index 4b230b94a..000000000 --- a/libc/bionic/strtold_l.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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. - */ - -#include - -long double strtold_l(const char *nptr, char **endptr, locale_t) { - return strtold(nptr, endptr); -} diff --git a/libc/bionic/strtoll_l.cpp b/libc/bionic/strtoll_l.cpp deleted file mode 100644 index 47b126e05..000000000 --- a/libc/bionic/strtoll_l.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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. - */ - -#include - -long long strtoll_l(const char *nptr, char **endptr, int base, locale_t) { - return strtoll(nptr, endptr, base); -} diff --git a/libc/bionic/strtoull_l.cpp b/libc/bionic/strtoull_l.cpp deleted file mode 100644 index 398ba0e94..000000000 --- a/libc/bionic/strtoull_l.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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. - */ - -#include - -unsigned long long strtoull_l(const char *nptr, char **endptr, int base, - locale_t) { - return strtoull(nptr, endptr, base); -} diff --git a/libc/bionic/strxfrm_l.cpp b/libc/bionic/strxfrm_l.cpp deleted file mode 100644 index afe3b965c..000000000 --- a/libc/bionic/strxfrm_l.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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. - */ - -#include - -size_t strxfrm_l(char *dest, const char *src, size_t n, locale_t) { - return strxfrm(dest, src, n); -} diff --git a/libc/include/string.h b/libc/include/string.h index 611c31a7a..f0bed100c 100644 --- a/libc/include/string.h +++ b/libc/include/string.h @@ -58,8 +58,11 @@ extern char* stpcpy(char* __restrict, const char* __restrict); extern char* strcpy(char* __restrict, const char* __restrict); extern char* strcat(char* __restrict, const char* __restrict); -extern int strcasecmp(const char *, const char *) __purefunc; -extern int strncasecmp(const char *, const char *, size_t) __purefunc; +int strcasecmp(const char*, const char*) __purefunc; +int strcasecmp_l(const char*, const char*, locale_t) __purefunc; +int strncasecmp(const char*, const char*, size_t) __purefunc; +int strncasecmp_l(const char*, const char*, size_t, locale_t) __purefunc; + extern char* strdup(const char *); extern char* strstr(const char *, const char *) __purefunc; @@ -68,6 +71,7 @@ extern char* strtok(char* __restrict, const char* __restrict); extern char* strtok_r(char* __restrict, const char* __restrict, char** __restrict); extern char* strerror(int); +extern char* strerror_l(int, locale_t); #if defined(__USE_GNU) extern char* strerror_r(int, char*, size_t) __RENAME(__gnu_strerror_r); #else /* POSIX */ diff --git a/libc/include/strings.h b/libc/include/strings.h index ae261cff6..1253006a0 100644 --- a/libc/include/strings.h +++ b/libc/include/strings.h @@ -41,22 +41,23 @@ #include #include +#include __BEGIN_DECLS #if defined(__BIONIC_FORTIFY) -#define bcopy(b1, b2, len) \ - (void)(__builtin___memmove_chk((b2), (b1), (len), __bos0(b2))) -#define bzero(b, len) \ - (void)(__builtin___memset_chk((b), '\0', (len), __bos0(b))) +#define bcopy(b1, b2, len) (void)(__builtin___memmove_chk((b2), (b1), (len), __bos0(b2))) +#define bzero(b, len) (void)(__builtin___memset_chk((b), '\0', (len), __bos0(b))) #else #define bcopy(b1, b2, len) (void)(__builtin_memmove((b2), (b1), (len))) #define bzero(b, len) (void)(__builtin_memset((b), '\0', (len))) #endif +int ffs(int); -int ffs(int); -int strcasecmp(const char *, const char *); -int strncasecmp(const char *, const char *, size_t); +int strcasecmp(const char*, const char*) __purefunc; +int strcasecmp_l(const char*, const char*, locale_t) __purefunc; +int strncasecmp(const char*, const char*, size_t) __purefunc; +int strncasecmp_l(const char*, const char*, size_t, locale_t) __purefunc; __END_DECLS diff --git a/libc/include/wchar.h b/libc/include/wchar.h index 10a78b897..9e279d3de 100644 --- a/libc/include/wchar.h +++ b/libc/include/wchar.h @@ -34,6 +34,7 @@ #include #include #include +#include #include @@ -112,6 +113,7 @@ extern int vwprintf(const wchar_t*, va_list); extern int vwscanf(const wchar_t*, va_list); extern size_t wcrtomb(char *, wchar_t, mbstate_t *); extern int wcscasecmp(const wchar_t *, const wchar_t *); +extern int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t); extern wchar_t *wcscat(wchar_t *, const wchar_t *); extern wchar_t *wcschr(const wchar_t *, wchar_t); extern int wcscmp(const wchar_t *, const wchar_t *); @@ -121,6 +123,7 @@ extern size_t wcscspn(const wchar_t *, const wchar_t *); extern size_t wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm *) __LIBC_ABI_PUBLIC__; extern size_t wcslen(const wchar_t *); extern int wcsncasecmp(const wchar_t *, const wchar_t *, size_t); +extern int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); extern wchar_t *wcsncat(wchar_t *, const wchar_t *, size_t); extern int wcsncmp(const wchar_t *, const wchar_t *, size_t); extern wchar_t *wcsncpy(wchar_t *, const wchar_t *, size_t); diff --git a/tests/strings_test.cpp b/tests/strings_test.cpp index 5200859fb..823aa4f0f 100644 --- a/tests/strings_test.cpp +++ b/tests/strings_test.cpp @@ -17,6 +17,7 @@ #include #include +#include #include TEST(strings, ffs) { @@ -30,3 +31,33 @@ TEST(strings, ffs) { ASSERT_EQ(27, ffs(0x04000000)); ASSERT_EQ(32, ffs(0x80000000)); } + +TEST(strings, strcasecmp) { + ASSERT_EQ(0, strcasecmp("hello", "HELLO")); + ASSERT_LT(strcasecmp("hello1", "hello2"), 0); + ASSERT_GT(strcasecmp("hello2", "hello1"), 0); +} + +TEST(strings, strcasecmp_l) { + locale_t l = newlocale(LC_ALL, "C", 0); + ASSERT_EQ(0, strcasecmp_l("hello", "HELLO", l)); + ASSERT_LT(strcasecmp_l("hello1", "hello2", l), 0); + ASSERT_GT(strcasecmp_l("hello2", "hello1", l), 0); + freelocale(l); +} + +TEST(strings, strncasecmp) { + ASSERT_EQ(0, strncasecmp("hello", "HELLO", 3)); + ASSERT_EQ(0, strncasecmp("abcXX", "ABCYY", 3)); + ASSERT_LT(strncasecmp("hello1", "hello2", 6), 0); + ASSERT_GT(strncasecmp("hello2", "hello1", 6), 0); +} + +TEST(strings, strncasecmp_l) { + locale_t l = newlocale(LC_ALL, "C", 0); + ASSERT_EQ(0, strncasecmp_l("hello", "HELLO", 3, l)); + ASSERT_EQ(0, strncasecmp_l("abcXX", "ABCYY", 3, l)); + ASSERT_LT(strncasecmp_l("hello1", "hello2", 6, l), 0); + ASSERT_GT(strncasecmp_l("hello2", "hello1", 6, l), 0); + freelocale(l); +}