summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-02-18 21:29:13 -0800
committerElliott Hughes <enh@google.com>2015-02-18 22:02:56 -0800
commit3cfb52aab2548df635e9672218cc433e14922fd3 (patch)
treeeebbf162a1e5e1ed8726a9129ea17a410ebaa3ed
parent3e1b5f46c07aef5983ecf2feb1c3369b2cd200c0 (diff)
downloadbionic-3cfb52aab2548df635e9672218cc433e14922fd3.zip
bionic-3cfb52aab2548df635e9672218cc433e14922fd3.tar.gz
bionic-3cfb52aab2548df635e9672218cc433e14922fd3.tar.bz2
Add GNU extensions mempcpy and wmemcpy.
Used by elfutils. On the bright side, they stopped using __mempcpy. Bug: 18374026 Change-Id: Id29bbe6ef1c5ed5a171bb6c32182f129d8332abb
-rw-r--r--libc/Android.mk2
-rw-r--r--libc/bionic/mempcpy.cpp33
-rw-r--r--libc/bionic/wmempcpy.cpp33
-rw-r--r--libc/include/string.h3
-rw-r--r--libc/include/wchar.h3
-rw-r--r--tests/string_test.cpp5
-rw-r--r--tests/wchar_test.cpp5
7 files changed, 84 insertions, 0 deletions
diff --git a/libc/Android.mk b/libc/Android.mk
index 7dc7cbf..9dd3864 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -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 :=
diff --git a/libc/bionic/mempcpy.cpp b/libc/bionic/mempcpy.cpp
new file mode 100644
index 0000000..b7b72f7
--- /dev/null
+++ b/libc/bionic/mempcpy.cpp
@@ -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;
+}
diff --git a/libc/bionic/wmempcpy.cpp b/libc/bionic/wmempcpy.cpp
new file mode 100644
index 0000000..54ebf86
--- /dev/null
+++ b/libc/bionic/wmempcpy.cpp
@@ -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;
+}
diff --git a/libc/include/string.h b/libc/include/string.h
index d67928c..fffe136 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -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;
diff --git a/libc/include/wchar.h b/libc/include/wchar.h
index cfd2299..ea6aca0 100644
--- a/libc/include/wchar.h
+++ b/libc/include/wchar.h
@@ -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 *, ...);
diff --git a/tests/string_test.cpp b/tests/string_test.cpp
index 66cf848..1d63c76 100644
--- a/tests/string_test.cpp
+++ b/tests/string_test.cpp
@@ -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)));
+}
diff --git a/tests/wchar_test.cpp b/tests/wchar_test.cpp
index a1d1501..e86d56d 100644
--- a/tests/wchar_test.cpp
+++ b/tests/wchar_test.cpp
@@ -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));
+}