Add GNU extensions mempcpy and wmemcpy.
Used by elfutils. On the bright side, they stopped using __mempcpy. Bug: 18374026 Change-Id: Id29bbe6ef1c5ed5a171bb6c32182f129d8332abb
This commit is contained in:
parent
3e1b5f46c0
commit
3cfb52aab2
@ -143,6 +143,7 @@ libc_bionic_ndk_src_files := \
|
||||
bionic/mbrtoc16.cpp \
|
||||
bionic/mbrtoc32.cpp \
|
||||
bionic/mbstate.cpp \
|
||||
bionic/mempcpy.cpp \
|
||||
bionic/mkdir.cpp \
|
||||
bionic/mkfifo.cpp \
|
||||
bionic/mknod.cpp \
|
||||
@ -214,6 +215,7 @@ libc_bionic_ndk_src_files := \
|
||||
bionic/wait.cpp \
|
||||
bionic/wchar.cpp \
|
||||
bionic/wctype.cpp \
|
||||
bionic/wmempcpy.cpp \
|
||||
|
||||
libc_bionic_src_files :=
|
||||
|
||||
|
33
libc/bionic/mempcpy.cpp
Normal file
33
libc/bionic/mempcpy.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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* mempcpy(void* dst, const void* src, size_t n) {
|
||||
return reinterpret_cast<char*>(memcpy(dst, src, n)) + n;
|
||||
}
|
33
libc/bionic/wmempcpy.cpp
Normal file
33
libc/bionic/wmempcpy.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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 <wchar.h>
|
||||
|
||||
wchar_t* wmempcpy(wchar_t* dst, const wchar_t* src, size_t n) {
|
||||
return wmemcpy(dst, src, n) + n;
|
||||
}
|
@ -44,6 +44,9 @@ extern void* memchr(const void *, int, size_t) __purefunc;
|
||||
extern void* memrchr(const void *, int, size_t) __purefunc;
|
||||
extern int memcmp(const void *, const void *, size_t) __purefunc;
|
||||
extern void* memcpy(void* __restrict, const void* __restrict, size_t);
|
||||
#if defined(__USE_GNU)
|
||||
extern void* mempcpy(void* __restrict, const void* __restrict, size_t);
|
||||
#endif
|
||||
extern void* memmove(void *, const void *, size_t);
|
||||
extern void* memset(void *, int, size_t);
|
||||
extern void* memmem(const void *, size_t, const void *, size_t) __purefunc;
|
||||
|
@ -151,6 +151,9 @@ extern int wcwidth(wchar_t);
|
||||
extern wchar_t *wmemchr(const wchar_t *, wchar_t, size_t);
|
||||
extern int wmemcmp(const wchar_t *, const wchar_t *, size_t);
|
||||
extern wchar_t *wmemcpy(wchar_t *, const wchar_t *, size_t);
|
||||
#if defined(__USE_GNU)
|
||||
extern wchar_t *wmempcpy(wchar_t *, const wchar_t *, size_t);
|
||||
#endif
|
||||
extern wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t);
|
||||
extern wchar_t *wmemset(wchar_t *, wchar_t, size_t);
|
||||
extern int wprintf(const wchar_t *, ...);
|
||||
|
@ -1395,3 +1395,8 @@ TEST(string, strnlen_147048) {
|
||||
EXPECT_EQ(0U, strnlen(heap_src, 1024*1024*1024));
|
||||
delete[] heap_src;
|
||||
}
|
||||
|
||||
TEST(string, mempcpy) {
|
||||
char dst[6];
|
||||
ASSERT_EQ(&dst[4], reinterpret_cast<char*>(mempcpy(dst, "hello", 4)));
|
||||
}
|
||||
|
@ -667,3 +667,8 @@ TEST(wchar, wcstoull_l_EINVAL) {
|
||||
wcstoull_l(L"123", NULL, 37, LC_GLOBAL_LOCALE);
|
||||
ASSERT_EQ(EINVAL, errno);
|
||||
}
|
||||
|
||||
TEST(wchar, wmempcpy) {
|
||||
wchar_t dst[6];
|
||||
ASSERT_EQ(&dst[4], wmempcpy(dst, L"hello", 4));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user