diff options
author | Elliott Hughes <enh@google.com> | 2012-10-01 17:35:49 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2012-10-01 17:35:49 -0700 |
commit | a89864a20b818621a1da10e88fda815334062f9f (patch) | |
tree | 7ebc6e1cf123c0f9d8ab50e775039e183990110b /libc/string | |
parent | d3bf954e9ffbdee8d732ccb6ad6143dc31b605fc (diff) | |
download | bionic-a89864a20b818621a1da10e88fda815334062f9f.zip bionic-a89864a20b818621a1da10e88fda815334062f9f.tar.gz bionic-a89864a20b818621a1da10e88fda815334062f9f.tar.bz2 |
Move non-upstream code into the libc/bionic directory.
I'll need at least one more pass, because there's some upstream code
lurking in libc/bionic, but this is still a step in the right direction.
Change-Id: I55927315972da8327ae01c5240ed587db17e8462
Diffstat (limited to 'libc/string')
-rw-r--r-- | libc/string/__memcpy_chk.c | 56 | ||||
-rw-r--r-- | libc/string/__memmove_chk.c | 55 | ||||
-rw-r--r-- | libc/string/__memset_chk.c | 54 | ||||
-rw-r--r-- | libc/string/__strcat_chk.c | 68 | ||||
-rw-r--r-- | libc/string/__strcpy_chk.c | 56 | ||||
-rw-r--r-- | libc/string/__strlcat_chk.c | 55 | ||||
-rw-r--r-- | libc/string/__strlcpy_chk.c | 55 | ||||
-rw-r--r-- | libc/string/__strlen_chk.c | 67 | ||||
-rw-r--r-- | libc/string/__strncat_chk.c | 72 | ||||
-rw-r--r-- | libc/string/__strncpy_chk.c | 55 | ||||
-rw-r--r-- | libc/string/memccpy.c | 47 | ||||
-rw-r--r-- | libc/string/memchr.c | 46 | ||||
-rw-r--r-- | libc/string/memcmp.c | 51 | ||||
-rw-r--r-- | libc/string/memcpy.c | 29 | ||||
-rw-r--r-- | libc/string/memmem.c | 64 | ||||
-rw-r--r-- | libc/string/memmove.c | 46 | ||||
-rw-r--r-- | libc/string/memrchr.c | 47 | ||||
-rw-r--r-- | libc/string/memset.c | 44 | ||||
-rw-r--r-- | libc/string/memswap.c | 43 | ||||
-rwxr-xr-x | libc/string/strcoll.c | 40 | ||||
-rw-r--r-- | libc/string/strndup.c | 44 | ||||
-rw-r--r-- | libc/string/strnlen.c | 38 | ||||
-rw-r--r-- | libc/string/strtotimeval.c | 63 |
23 files changed, 0 insertions, 1195 deletions
diff --git a/libc/string/__memcpy_chk.c b/libc/string/__memcpy_chk.c deleted file mode 100644 index 10334ba..0000000 --- a/libc/string/__memcpy_chk.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2012 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. - */ - -#undef _FORTIFY_SOURCE -#include <string.h> -#include <stdlib.h> -#include <private/logd.h> - -/* - * Runtime implementation of __memcpy_chk. - * - * See - * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html - * http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html - * for details. - * - * This memcpy check is called if _FORTIFY_SOURCE is defined and - * greater than 0. - */ -void *__memcpy_chk(void *dest, const void *src, - size_t copy_amount, size_t dest_len) -{ - if (__builtin_expect(copy_amount > dest_len, 0)) { - __libc_android_log_print(ANDROID_LOG_FATAL, "libc", - "*** memcpy buffer overflow detected ***\n"); - __libc_android_log_event_uid(BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW); - abort(); - } - - return memcpy(dest, src, copy_amount); -} diff --git a/libc/string/__memmove_chk.c b/libc/string/__memmove_chk.c deleted file mode 100644 index 529eb8f..0000000 --- a/libc/string/__memmove_chk.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2012 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 <string.h> -#include <stdlib.h> -#include <private/logd.h> - -/* - * Runtime implementation of __builtin____memmove_chk. - * - * See - * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html - * http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html - * for details. - * - * This memmove check is called if _FORTIFY_SOURCE is defined and - * greater than 0. - */ -void *__memmove_chk (void *dest, const void *src, - size_t len, size_t dest_len) -{ - if (len > dest_len) { - __libc_android_log_print(ANDROID_LOG_FATAL, "libc", - "*** memmove buffer overflow detected ***\n"); - __libc_android_log_event_uid(BIONIC_EVENT_MEMMOVE_BUFFER_OVERFLOW); - abort(); - } - - return memmove(dest, src, len); -} diff --git a/libc/string/__memset_chk.c b/libc/string/__memset_chk.c deleted file mode 100644 index 0904c03..0000000 --- a/libc/string/__memset_chk.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2012 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 <string.h> -#include <stdlib.h> -#include <private/logd.h> - -/* - * Runtime implementation of __builtin____memset_chk. - * - * See - * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html - * http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html - * for details. - * - * This memset check is called if _FORTIFY_SOURCE is defined and - * greater than 0. - */ -void *__memset_chk (void *dest, int c, size_t n, size_t dest_len) -{ - if (n > dest_len) { - __libc_android_log_print(ANDROID_LOG_FATAL, "libc", - "*** memset buffer overflow detected ***\n"); - __libc_android_log_event_uid(BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW); - abort(); - } - - return memset(dest, c, n); -} diff --git a/libc/string/__strcat_chk.c b/libc/string/__strcat_chk.c deleted file mode 100644 index 4665d66..0000000 --- a/libc/string/__strcat_chk.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2012 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 <string.h> -#include <stdlib.h> -#include <private/logd.h> -#include <safe_iop.h> - -/* - * Runtime implementation of __builtin____strcat_chk. - * - * See - * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html - * http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html - * for details. - * - * This strcat check is called if _FORTIFY_SOURCE is defined and - * greater than 0. - */ -char *__strcat_chk (char *dest, const char *src, size_t dest_buf_size) -{ - // TODO: optimize so we don't scan src/dest twice. - size_t src_len = strlen(src); - size_t dest_len = strlen(dest); - size_t sum; - - // sum = src_len + dest_len + 1 (with overflow protection) - if (!safe_add3(&sum, src_len, dest_len, 1U)) { - __libc_android_log_print(ANDROID_LOG_FATAL, "libc", - "*** strcat integer overflow detected ***\n"); - __libc_android_log_event_uid(BIONIC_EVENT_STRCAT_INTEGER_OVERFLOW); - abort(); - } - - if (sum > dest_buf_size) { - __libc_android_log_print(ANDROID_LOG_FATAL, "libc", - "*** strcat buffer overflow detected ***\n"); - __libc_android_log_event_uid(BIONIC_EVENT_STRNCAT_BUFFER_OVERFLOW); - abort(); - } - - return strcat(dest, src); -} diff --git a/libc/string/__strcpy_chk.c b/libc/string/__strcpy_chk.c deleted file mode 100644 index 79486b4..0000000 --- a/libc/string/__strcpy_chk.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2012 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 <string.h> -#include <stdlib.h> -#include <private/logd.h> - -/* - * Runtime implementation of __builtin____strcpy_chk. - * - * See - * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html - * http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html - * for details. - * - * This strcpy check is called if _FORTIFY_SOURCE is defined and - * greater than 0. - */ -char *__strcpy_chk (char *dest, const char *src, size_t dest_len) -{ - // TODO: optimize so we don't scan src twice. - size_t src_len = strlen(src) + 1; - if (src_len > dest_len) { - __libc_android_log_print(ANDROID_LOG_FATAL, "libc", - "*** strcpy buffer overflow detected ***\n"); - __libc_android_log_event_uid(BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW); - abort(); - } - - return strcpy(dest, src); -} diff --git a/libc/string/__strlcat_chk.c b/libc/string/__strlcat_chk.c deleted file mode 100644 index b895fb8..0000000 --- a/libc/string/__strlcat_chk.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2012 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 <string.h> -#include <stdlib.h> -#include <private/logd.h> - -/* - * __strlcat_chk. Called in place of strlcat() when we know the - * size of the buffer we're writing into. - * - * See - * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html - * http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html - * for details. - * - * This strlcat check is called if _FORTIFY_SOURCE is defined and - * greater than 0. - */ -size_t __strlcat_chk(char *dest, const char *src, - size_t supplied_size, size_t dest_len_from_compiler) -{ - if (supplied_size > dest_len_from_compiler) { - __libc_android_log_print(ANDROID_LOG_FATAL, "libc", - "*** strlcat buffer overflow detected ***\n"); - abort(); - } - - return strlcat(dest, src, supplied_size); -} diff --git a/libc/string/__strlcpy_chk.c b/libc/string/__strlcpy_chk.c deleted file mode 100644 index 752c86c..0000000 --- a/libc/string/__strlcpy_chk.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2012 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 <string.h> -#include <stdlib.h> -#include <private/logd.h> - -/* - * __strlcpy_chk. Called in place of strlcpy() when we know the - * size of the buffer we're writing into. - * - * See - * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html - * http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html - * for details. - * - * This strlcpy check is called if _FORTIFY_SOURCE is defined and - * greater than 0. - */ -size_t __strlcpy_chk(char *dest, const char *src, - size_t supplied_size, size_t dest_len_from_compiler) -{ - if (supplied_size > dest_len_from_compiler) { - __libc_android_log_print(ANDROID_LOG_FATAL, "libc", - "*** strlcpy buffer overflow detected ***\n"); - abort(); - } - - return strlcpy(dest, src, supplied_size); -} diff --git a/libc/string/__strlen_chk.c b/libc/string/__strlen_chk.c deleted file mode 100644 index 43e7e80..0000000 --- a/libc/string/__strlen_chk.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2012 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 <string.h> -#include <stdlib.h> -#include <private/logd.h> - -/* - * Runtime implementation of __strlen_chk. - * - * See - * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html - * http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html - * for details. - * - * This strlen check is called if _FORTIFY_SOURCE is defined and - * greater than 0. - * - * This test is designed to detect code such as: - * - * int main() { - * char buf[10]; - * memcpy(buf, "1234567890", sizeof(buf)); - * size_t len = strlen(buf); // segfault here with _FORTIFY_SOURCE - * printf("%d\n", len); - * return 0; - * } - * - * or anytime strlen reads beyond an object boundary. - */ -size_t __strlen_chk(const char *s, size_t s_len) -{ - size_t ret = strlen(s); - - if (__builtin_expect(ret >= s_len, 0)) { - __libc_android_log_print(ANDROID_LOG_FATAL, "libc", - "*** strlen read overflow detected ***\n"); - abort(); - } - - return ret; -} diff --git a/libc/string/__strncat_chk.c b/libc/string/__strncat_chk.c deleted file mode 100644 index 2036c9f..0000000 --- a/libc/string/__strncat_chk.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2012 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 <string.h> -#include <stdlib.h> -#include <private/logd.h> -#include <safe_iop.h> - -/* - * Runtime implementation of __builtin____strncat_chk. - * - * See - * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html - * http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html - * for details. - * - * This strncat check is called if _FORTIFY_SOURCE is defined and - * greater than 0. - */ -char *__strncat_chk (char *dest, const char *src, - size_t len, size_t dest_buf_size) -{ - // TODO: optimize so we don't scan src/dest twice. - size_t dest_len = strlen(dest); - size_t src_len = strlen(src); - if (src_len > len) { - src_len = len; - } - - size_t sum; - // sum = src_len + dest_len + 1 (with overflow protection) - if (!safe_add3(&sum, src_len, dest_len, 1U)) { - __libc_android_log_print(ANDROID_LOG_FATAL, "libc", - "*** strncat integer overflow detected ***\n"); - __libc_android_log_event_uid(BIONIC_EVENT_STRNCAT_INTEGER_OVERFLOW); - abort(); - } - - if (sum > dest_buf_size) { - __libc_android_log_print(ANDROID_LOG_FATAL, "libc", - "*** strncat buffer overflow detected ***\n"); - __libc_android_log_event_uid(BIONIC_EVENT_STRNCAT_BUFFER_OVERFLOW); - abort(); - } - - return strncat(dest, src, len); -} diff --git a/libc/string/__strncpy_chk.c b/libc/string/__strncpy_chk.c deleted file mode 100644 index 3f9e9fb..0000000 --- a/libc/string/__strncpy_chk.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2012 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 <string.h> -#include <stdlib.h> -#include <private/logd.h> - -/* - * Runtime implementation of __builtin____strncpy_chk. - * - * See - * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html - * http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html - * for details. - * - * This strncpy check is called if _FORTIFY_SOURCE is defined and - * greater than 0. - */ -char *__strncpy_chk (char *dest, const char *src, - size_t len, size_t dest_len) -{ - if (len > dest_len) { - __libc_android_log_print(ANDROID_LOG_FATAL, "libc", - "*** strncpy buffer overflow detected ***\n"); - __libc_android_log_event_uid(BIONIC_EVENT_STRNCPY_BUFFER_OVERFLOW); - abort(); - } - - return strncpy(dest, src, len); -} diff --git a/libc/string/memccpy.c b/libc/string/memccpy.c deleted file mode 100644 index 789fde6..0000000 --- a/libc/string/memccpy.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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. - */ -#include <stddef.h> -#include <string.h> - -void *memccpy(void *dst, const void *src, int c, size_t n) -{ - char* q = dst; - const char* p = src; - const char* p_end = p + n; - char ch = ~(char)c; /* ensure ch != c */ - - for (;;) { - if (ch == c || p >= p_end) break; - *q++ = ch = *p++; - } - - if (p >= p_end && ch != c) - return NULL; - - return q; -} diff --git a/libc/string/memchr.c b/libc/string/memchr.c deleted file mode 100644 index b14167a..0000000 --- a/libc/string/memchr.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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. - */ -#include <stddef.h> -#include <string.h> - -void *memchr(const void *s, int c, size_t n) -{ - const unsigned char* p = s; - const unsigned char* end = p + n; - - for (;;) { - if (p >= end || p[0] == c) break; p++; - if (p >= end || p[0] == c) break; p++; - if (p >= end || p[0] == c) break; p++; - if (p >= end || p[0] == c) break; p++; - } - if (p >= end) - return NULL; - else - return (void*) p; -} diff --git a/libc/string/memcmp.c b/libc/string/memcmp.c deleted file mode 100644 index 8640954..0000000 --- a/libc/string/memcmp.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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. - */ -#include <string.h> - -int memcmp(const void *s1, const void *s2, size_t n) -{ - const unsigned char* p1 = s1; - const unsigned char* end1 = p1 + n; - const unsigned char* p2 = s2; - int d = 0; - - for (;;) { - if (d || p1 >= end1) break; - d = (int)*p1++ - (int)*p2++; - - if (d || p1 >= end1) break; - d = (int)*p1++ - (int)*p2++; - - if (d || p1 >= end1) break; - d = (int)*p1++ - (int)*p2++; - - if (d || p1 >= end1) break; - d = (int)*p1++ - (int)*p2++; - } - return d; -} diff --git a/libc/string/memcpy.c b/libc/string/memcpy.c deleted file mode 100644 index dea78b2..0000000 --- a/libc/string/memcpy.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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. - */ -#define MEMCOPY -#include "bcopy.c" diff --git a/libc/string/memmem.c b/libc/string/memmem.c deleted file mode 100644 index e72501b..0000000 --- a/libc/string/memmem.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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. - */ -/* - * This uses the "Not So Naive" algorithm, a very simple but - * usually effective algorithm, see: - * http://www-igm.univ-mlv.fr/~lecroq/string/ - */ -#include <string.h> - -void *memmem(const void *haystack, size_t n, const void *needle, size_t m) -{ - if (m > n || !m || !n) - return NULL; - - if (__builtin_expect((m > 1), 1)) { - const unsigned char* y = (const unsigned char*) haystack; - const unsigned char* x = (const unsigned char*) needle; - size_t j = 0; - size_t k = 1, l = 2; - - if (x[0] == x[1]) { - k = 2; - l = 1; - } - while (j <= n-m) { - if (x[1] != y[j+1]) { - j += k; - } else { - if (!memcmp(x+2, y+j+2, m-2) && x[0] == y[j]) - return (void*) &y[j]; - j += l; - } - } - } else { - /* degenerate case */ - return memchr(haystack, ((unsigned char*)needle)[0], n); - } - return NULL; -} diff --git a/libc/string/memmove.c b/libc/string/memmove.c deleted file mode 100644 index a9fc1b5..0000000 --- a/libc/string/memmove.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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. - */ -#undef _FORTIFY_SOURCE -#include <string.h> -#include <strings.h> - -void *memmove(void *dst, const void *src, size_t n) -{ - const char *p = src; - char *q = dst; - /* We can use the optimized memcpy if the source and destination - * don't overlap. - */ - if (__builtin_expect(((q < p) && ((size_t)(p - q) >= n)) - || ((p < q) && ((size_t)(q - p) >= n)), 1)) { - return memcpy(dst, src, n); - } else { - bcopy(src, dst, n); - return dst; - } -} diff --git a/libc/string/memrchr.c b/libc/string/memrchr.c deleted file mode 100644 index aeb5643..0000000 --- a/libc/string/memrchr.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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. - */ -#include <stddef.h> -#include <string.h> - -void *memrchr(const void *s, int c, size_t n) -{ - if (n > 0) { - const char* p = (const char*) s; - const char* q = p + n; - - while (1) { - q--; if (q < p || q[0] == (char) c) break; - q--; if (q < p || q[0] == (char) c) break; - q--; if (q < p || q[0] == (char) c) break; - q--; if (q < p || q[0] == (char) c) break; - } - if (q >= p) - return (void*)q; - } - return NULL; -} diff --git a/libc/string/memset.c b/libc/string/memset.c deleted file mode 100644 index 41dafb2..0000000 --- a/libc/string/memset.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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. - */ -#include <string.h> -#include <stdint.h> - -void* memset(void* dst, int c, size_t n) -{ - char* q = dst; - char* end = q + n; - - for (;;) { - if (q >= end) break; *q++ = (char) c; - if (q >= end) break; *q++ = (char) c; - if (q >= end) break; *q++ = (char) c; - if (q >= end) break; *q++ = (char) c; - } - - return dst; -} diff --git a/libc/string/memswap.c b/libc/string/memswap.c deleted file mode 100644 index 35b0b32..0000000 --- a/libc/string/memswap.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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. - */ -#include <string.h> - -void memswap(void *m1, void *m2, size_t n) -{ - char* p = m1; - char* p_end = p + n; - char* q = m2; - - while (p < p_end) { - char tmp = *p; - *p = *q; - *q = tmp; - p++; - q++; - } -} diff --git a/libc/string/strcoll.c b/libc/string/strcoll.c deleted file mode 100755 index e3b1ec3..0000000 --- a/libc/string/strcoll.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2009 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 <string.h> - -/* - * Compare strings using the current locale. Since Bionic really does not - * support locales, we assume we always use the C locale and call strcmp. - * - * This function is provided to make libstdc++-v3 usable. - */ -int -strcoll(const char *s1, const char *s2) -{ - return strcmp(s1, s2); -} diff --git a/libc/string/strndup.c b/libc/string/strndup.c deleted file mode 100644 index 9dca79c..0000000 --- a/libc/string/strndup.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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. - */ -#include <string.h> -#include <stdlib.h> - -char* strndup(const char* s, size_t n) -{ - size_t slen = (size_t)strlen(s); - char* copy; - - if (slen < n) - n = slen; - copy = malloc(n+1); - if (copy) { - memcpy(copy, s, n); - copy[n] = 0; - } - return copy; -} diff --git a/libc/string/strnlen.c b/libc/string/strnlen.c deleted file mode 100644 index 2c6f60a..0000000 --- a/libc/string/strnlen.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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. - */ -#include <string.h> - -size_t strnlen(const char* str, size_t maxlen) -{ - char* p = memchr(str, 0, maxlen); - - if (p == NULL) - return maxlen; - else - return (p - str); -} diff --git a/libc/string/strtotimeval.c b/libc/string/strtotimeval.c deleted file mode 100644 index 1c132ec..0000000 --- a/libc/string/strtotimeval.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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. - */ -#include <ctype.h> -#include <inttypes.h> -#include <stdlib.h> -#include <sys/time.h> - -char * strtotimeval (const char *str, struct timeval *ts) -{ - int n; - char *s, *s0; - long fs; /* Fractional seconds */ - - ts->tv_sec = strtoumax(str, &s, 10); - fs = 0; - - if ( *s == '.' ) { - int count; - - s0 = s+1; - - /* read up to 6 digits */ - fs = 0; - count = 0; - while ( *s && isdigit(*s) ) - { - if ( ++count < 7 ) - fs = fs*10 + (*s - '0'); - s++; - } - - for ( ; count < 6; count++ ) - fs *= 10; - } - - ts->tv_usec = fs; - return s; -} |