summaryrefslogtreecommitdiffstats
path: root/libc/bionic
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2012-10-01 17:35:49 -0700
committerElliott Hughes <enh@google.com>2012-10-01 17:35:49 -0700
commita89864a20b818621a1da10e88fda815334062f9f (patch)
tree7ebc6e1cf123c0f9d8ab50e775039e183990110b /libc/bionic
parentd3bf954e9ffbdee8d732ccb6ad6143dc31b605fc (diff)
downloadbionic-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/bionic')
-rw-r--r--libc/bionic/__fgets_chk.c60
-rw-r--r--libc/bionic/__memcpy_chk.c56
-rw-r--r--libc/bionic/__memmove_chk.c55
-rw-r--r--libc/bionic/__memset_chk.c54
-rw-r--r--libc/bionic/__snprintf_chk.c59
-rw-r--r--libc/bionic/__sprintf_chk.c58
-rw-r--r--libc/bionic/__strcat_chk.c68
-rw-r--r--libc/bionic/__strcpy_chk.c56
-rw-r--r--libc/bionic/__strlcat_chk.c55
-rw-r--r--libc/bionic/__strlcpy_chk.c55
-rw-r--r--libc/bionic/__strlen_chk.c67
-rw-r--r--libc/bionic/__strncat_chk.c72
-rw-r--r--libc/bionic/__strncpy_chk.c55
-rw-r--r--libc/bionic/__vsnprintf_chk.c60
-rw-r--r--libc/bionic/__vsprintf_chk.c61
-rw-r--r--libc/bionic/atoi.c33
-rw-r--r--libc/bionic/atol.c33
-rw-r--r--libc/bionic/atoll.c33
-rw-r--r--libc/bionic/bindresvport.c72
-rw-r--r--libc/bionic/brk.c45
-rw-r--r--libc/bionic/daemon.c68
-rw-r--r--libc/bionic/ether_aton.c89
-rw-r--r--libc/bionic/ether_ntoa.c55
-rw-r--r--libc/bionic/eventfd.c53
-rw-r--r--libc/bionic/fcntl.c43
-rw-r--r--libc/bionic/flockfile.c75
-rw-r--r--libc/bionic/fstatfs.c35
-rw-r--r--libc/bionic/ftime.c49
-rw-r--r--libc/bionic/ftok.c40
-rw-r--r--libc/bionic/getdtablesize.c39
-rw-r--r--libc/bionic/gethostname.c51
-rw-r--r--libc/bionic/getpgrp.c33
-rw-r--r--libc/bionic/getpriority.c37
-rw-r--r--libc/bionic/getpt.c34
-rw-r--r--libc/bionic/initgroups.c58
-rw-r--r--libc/bionic/isatty.c39
-rw-r--r--libc/bionic/issetugid.c35
-rw-r--r--libc/bionic/locale.c34
-rw-r--r--libc/bionic/lseek64.c40
-rw-r--r--libc/bionic/memccpy.c47
-rw-r--r--libc/bionic/memchr.c46
-rw-r--r--libc/bionic/memcmp.c51
-rw-r--r--libc/bionic/memcpy.c29
-rw-r--r--libc/bionic/memmem.c64
-rw-r--r--libc/bionic/memmove.c46
-rw-r--r--libc/bionic/memrchr.c47
-rw-r--r--libc/bionic/memset.c44
-rw-r--r--libc/bionic/memswap.c43
-rw-r--r--libc/bionic/mmap.c50
-rw-r--r--libc/bionic/open.c65
-rw-r--r--libc/bionic/openat.c66
-rw-r--r--libc/bionic/opendir.c273
-rw-r--r--libc/bionic/pathconf.c270
-rw-r--r--libc/bionic/perror.c44
-rw-r--r--libc/bionic/pread.c35
-rw-r--r--libc/bionic/pselect.c59
-rw-r--r--libc/bionic/ptsname.c44
-rw-r--r--libc/bionic/ptsname_r.c58
-rw-r--r--libc/bionic/pwrite.c35
-rw-r--r--libc/bionic/raise.c34
-rw-r--r--libc/bionic/reboot.c34
-rw-r--r--libc/bionic/recv.c34
-rw-r--r--libc/bionic/sbrk.c60
-rw-r--r--libc/bionic/send.c34
-rw-r--r--libc/bionic/setegid.c33
-rw-r--r--libc/bionic/seteuid.c37
-rw-r--r--libc/bionic/setpgrp.c33
-rw-r--r--libc/bionic/setresuid.c38
-rw-r--r--libc/bionic/setreuid.c37
-rw-r--r--libc/bionic/setuid.c37
-rw-r--r--libc/bionic/sigblock.c50
-rw-r--r--libc/bionic/siginterrupt.c45
-rw-r--r--libc/bionic/siglist.c33
-rw-r--r--libc/bionic/signal.c57
-rw-r--r--libc/bionic/signame.c33
-rw-r--r--libc/bionic/sigsetmask.c50
-rw-r--r--libc/bionic/sigsuspend.c43
-rw-r--r--libc/bionic/sigwait.c83
-rw-r--r--libc/bionic/sleep.c52
-rw-r--r--libc/bionic/socketcalls.c259
-rw-r--r--libc/bionic/statfs.c35
-rwxr-xr-xlibc/bionic/strcoll.c40
-rw-r--r--libc/bionic/strndup.c44
-rw-r--r--libc/bionic/strnlen.c38
-rw-r--r--libc/bionic/strntoimax.c34
-rw-r--r--libc/bionic/strntoumax.c95
-rw-r--r--libc/bionic/strtotimeval.c63
-rw-r--r--libc/bionic/sysconf.c341
-rw-r--r--libc/bionic/tcgetpgrp.c34
-rw-r--r--libc/bionic/tcsetpgrp.c33
-rw-r--r--libc/bionic/umount.c35
-rw-r--r--libc/bionic/unlockpt.c36
-rw-r--r--libc/bionic/usleep.c55
-rw-r--r--libc/bionic/wait.c53
-rw-r--r--libc/bionic/wchar.c330
-rw-r--r--libc/bionic/wcscoll.c39
96 files changed, 5851 insertions, 0 deletions
diff --git a/libc/bionic/__fgets_chk.c b/libc/bionic/__fgets_chk.c
new file mode 100644
index 0000000..19123b9
--- /dev/null
+++ b/libc/bionic/__fgets_chk.c
@@ -0,0 +1,60 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <private/logd.h>
+
+/*
+ * __fgets_chk. Called in place of fgets() when we know the
+ * size of the buffer we're writing into.
+ *
+ * See
+ * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
+ * for details.
+ *
+ * This fgets check is called if _FORTIFY_SOURCE is defined and
+ * greater than 0.
+ */
+char *__fgets_chk(char *dest, int supplied_size,
+ FILE *stream, size_t dest_len_from_compiler)
+{
+ if (supplied_size < 0) {
+ __libc_android_log_print(ANDROID_LOG_FATAL, "libc",
+ "*** fgets buffer size less than 0 ***\n");
+ abort();
+ }
+
+ if (((size_t) supplied_size) > dest_len_from_compiler) {
+ __libc_android_log_print(ANDROID_LOG_FATAL, "libc",
+ "*** fgets buffer overflow detected ***\n");
+ abort();
+ }
+
+ return fgets(dest, supplied_size, stream);
+}
diff --git a/libc/bionic/__memcpy_chk.c b/libc/bionic/__memcpy_chk.c
new file mode 100644
index 0000000..10334ba
--- /dev/null
+++ b/libc/bionic/__memcpy_chk.c
@@ -0,0 +1,56 @@
+/*
+ * 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/bionic/__memmove_chk.c b/libc/bionic/__memmove_chk.c
new file mode 100644
index 0000000..529eb8f
--- /dev/null
+++ b/libc/bionic/__memmove_chk.c
@@ -0,0 +1,55 @@
+/*
+ * 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/bionic/__memset_chk.c b/libc/bionic/__memset_chk.c
new file mode 100644
index 0000000..0904c03
--- /dev/null
+++ b/libc/bionic/__memset_chk.c
@@ -0,0 +1,54 @@
+/*
+ * 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/bionic/__snprintf_chk.c b/libc/bionic/__snprintf_chk.c
new file mode 100644
index 0000000..dbda3db
--- /dev/null
+++ b/libc/bionic/__snprintf_chk.c
@@ -0,0 +1,59 @@
+/*
+ * 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 <stdio.h>
+#include <stdarg.h>
+
+/*
+ * Runtime implementation of __builtin____snprintf_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 snprintf check is called if _FORTIFY_SOURCE is defined and
+ * greater than 0.
+ */
+int __snprintf_chk(
+ char *dest,
+ size_t supplied_size,
+ int flags,
+ size_t dest_len_from_compiler,
+ const char *format, ...)
+{
+ va_list va;
+ int retval;
+
+ va_start(va, format);
+ retval = __vsnprintf_chk(dest, supplied_size, flags,
+ dest_len_from_compiler, format, va);
+ va_end(va);
+
+ return retval;
+}
diff --git a/libc/bionic/__sprintf_chk.c b/libc/bionic/__sprintf_chk.c
new file mode 100644
index 0000000..67acbe1
--- /dev/null
+++ b/libc/bionic/__sprintf_chk.c
@@ -0,0 +1,58 @@
+/*
+ * 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 <stdio.h>
+#include <stdarg.h>
+
+/*
+ * Runtime implementation of __builtin____sprintf_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 sprintf check is called if _FORTIFY_SOURCE is defined and
+ * greater than 0.
+ */
+int __sprintf_chk(
+ char *dest,
+ int flags,
+ size_t dest_len_from_compiler,
+ const char *format, ...)
+{
+ va_list va;
+ int retval;
+
+ va_start(va, format);
+ retval = __vsprintf_chk(dest, flags,
+ dest_len_from_compiler, format, va);
+ va_end(va);
+
+ return retval;
+}
diff --git a/libc/bionic/__strcat_chk.c b/libc/bionic/__strcat_chk.c
new file mode 100644
index 0000000..4665d66
--- /dev/null
+++ b/libc/bionic/__strcat_chk.c
@@ -0,0 +1,68 @@
+/*
+ * 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/bionic/__strcpy_chk.c b/libc/bionic/__strcpy_chk.c
new file mode 100644
index 0000000..79486b4
--- /dev/null
+++ b/libc/bionic/__strcpy_chk.c
@@ -0,0 +1,56 @@
+/*
+ * 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/bionic/__strlcat_chk.c b/libc/bionic/__strlcat_chk.c
new file mode 100644
index 0000000..b895fb8
--- /dev/null
+++ b/libc/bionic/__strlcat_chk.c
@@ -0,0 +1,55 @@
+/*
+ * 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/bionic/__strlcpy_chk.c b/libc/bionic/__strlcpy_chk.c
new file mode 100644
index 0000000..752c86c
--- /dev/null
+++ b/libc/bionic/__strlcpy_chk.c
@@ -0,0 +1,55 @@
+/*
+ * 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/bionic/__strlen_chk.c b/libc/bionic/__strlen_chk.c
new file mode 100644
index 0000000..43e7e80
--- /dev/null
+++ b/libc/bionic/__strlen_chk.c
@@ -0,0 +1,67 @@
+/*
+ * 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/bionic/__strncat_chk.c b/libc/bionic/__strncat_chk.c
new file mode 100644
index 0000000..2036c9f
--- /dev/null
+++ b/libc/bionic/__strncat_chk.c
@@ -0,0 +1,72 @@
+/*
+ * 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/bionic/__strncpy_chk.c b/libc/bionic/__strncpy_chk.c
new file mode 100644
index 0000000..3f9e9fb
--- /dev/null
+++ b/libc/bionic/__strncpy_chk.c
@@ -0,0 +1,55 @@
+/*
+ * 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/bionic/__vsnprintf_chk.c b/libc/bionic/__vsnprintf_chk.c
new file mode 100644
index 0000000..a1a1039
--- /dev/null
+++ b/libc/bionic/__vsnprintf_chk.c
@@ -0,0 +1,60 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <private/logd.h>
+
+/*
+ * Runtime implementation of __builtin____vsnprintf_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 vsnprintf check is called if _FORTIFY_SOURCE is defined and
+ * greater than 0.
+ */
+int __vsnprintf_chk(
+ char *dest,
+ size_t supplied_size,
+ int flags,
+ size_t dest_len_from_compiler,
+ const char *format,
+ va_list va)
+{
+ if (supplied_size > dest_len_from_compiler) {
+ __libc_android_log_print(ANDROID_LOG_FATAL, "libc",
+ "*** vsnprintf buffer overflow detected ***\n");
+ abort();
+ }
+
+ return vsnprintf(dest, supplied_size, format, va);
+}
diff --git a/libc/bionic/__vsprintf_chk.c b/libc/bionic/__vsprintf_chk.c
new file mode 100644
index 0000000..8a809fc
--- /dev/null
+++ b/libc/bionic/__vsprintf_chk.c
@@ -0,0 +1,61 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <private/logd.h>
+
+/*
+ * Runtime implementation of __builtin____vsprintf_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 vsprintf check is called if _FORTIFY_SOURCE is defined and
+ * greater than 0.
+ */
+int __vsprintf_chk(
+ char *dest,
+ int flags,
+ size_t dest_len_from_compiler,
+ const char *format,
+ va_list va)
+{
+ int ret = vsnprintf(dest, dest_len_from_compiler, format, va);
+
+ if ((size_t) ret >= dest_len_from_compiler) {
+ __libc_android_log_print(ANDROID_LOG_FATAL, "libc",
+ "*** vsprintf buffer overflow detected ***\n");
+ abort();
+ }
+
+ return ret;
+}
diff --git a/libc/bionic/atoi.c b/libc/bionic/atoi.c
new file mode 100644
index 0000000..9a65543
--- /dev/null
+++ b/libc/bionic/atoi.c
@@ -0,0 +1,33 @@
+/*
+ * 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 <inttypes.h>
+
+int atoi(const char* s)
+{
+ return (int)strtoimax(s, NULL, 10);
+}
diff --git a/libc/bionic/atol.c b/libc/bionic/atol.c
new file mode 100644
index 0000000..83dc05c
--- /dev/null
+++ b/libc/bionic/atol.c
@@ -0,0 +1,33 @@
+/*
+ * 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 <inttypes.h>
+
+long atol(const char* s)
+{
+ return (long)strtoimax(s, NULL, 10);
+}
diff --git a/libc/bionic/atoll.c b/libc/bionic/atoll.c
new file mode 100644
index 0000000..953878f
--- /dev/null
+++ b/libc/bionic/atoll.c
@@ -0,0 +1,33 @@
+/*
+ * 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 <inttypes.h>
+
+long long atoll(const char* s)
+{
+ return (long long)strtoimax(s, NULL, 10);
+}
diff --git a/libc/bionic/bindresvport.c b/libc/bionic/bindresvport.c
new file mode 100644
index 0000000..5d9ad2b
--- /dev/null
+++ b/libc/bionic/bindresvport.c
@@ -0,0 +1,72 @@
+/*
+ * 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 <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <string.h>
+#include <unistd.h>
+
+#define START_PORT 600
+#define END_PORT IPPORT_RESERVED
+#define NUM_PORTS (END_PORT - START_PORT)
+
+int bindresvport(int sd, struct sockaddr_in *sin)
+{
+ static short port;
+ struct sockaddr_in sin0;
+ int nn, ret;
+
+ if (sin == NULL) {
+ sin = &sin0;
+ memset( sin, 0, sizeof *sin );
+ sin->sin_family = AF_INET;
+ } else if (sin->sin_family != AF_INET) {
+ errno = EPFNOSUPPORT;
+ return -1;
+ }
+
+ if (port == 0) {
+ port = START_PORT + (getpid() % NUM_PORTS);
+ }
+
+ for (nn = NUM_PORTS; nn > 0; nn--, port++)
+ {
+ if (port == END_PORT)
+ port = START_PORT;
+
+ sin->sin_port = htons(port);
+ do {
+ ret = bind(sd, (struct sockaddr*)sin, sizeof(*sin));
+ } while (ret < 0 && errno == EINTR);
+
+ if (!ret)
+ break;
+ }
+ return ret;
+}
diff --git a/libc/bionic/brk.c b/libc/bionic/brk.c
new file mode 100644
index 0000000..bf2f108
--- /dev/null
+++ b/libc/bionic/brk.c
@@ -0,0 +1,45 @@
+/*
+ * 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 <unistd.h>
+#include <sys/types.h>
+
+/* shared with sbrk.c */
+char *__bionic_brk;
+
+int brk(void* end_data)
+{
+ char* new_brk = __brk( end_data );
+
+ if (new_brk != end_data)
+ return -1;
+
+ __bionic_brk = new_brk;
+
+ return 0;
+}
diff --git a/libc/bionic/daemon.c b/libc/bionic/daemon.c
new file mode 100644
index 0000000..8181d16
--- /dev/null
+++ b/libc/bionic/daemon.c
@@ -0,0 +1,68 @@
+/*
+ * 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 <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+int daemon( int nochdir, int noclose )
+{
+ pid_t pid;
+
+ if ( !nochdir && chdir("/") != 0 )
+ return -1;
+
+ if ( !noclose )
+ {
+ int fd = open("/dev/null", O_RDWR);
+
+ if ( fd < 0 )
+ return -1;
+
+ if ( dup2( fd, 0 ) < 0 ||
+ dup2( fd, 1 ) < 0 ||
+ dup2( fd, 2 ) < 0 )
+ {
+ close(fd);
+ return -1;
+ }
+ close(fd);
+ }
+
+ pid = fork();
+ if (pid < 0)
+ return -1;
+
+ if (pid > 0)
+ _exit(0);
+
+ if ( setsid() < 0 )
+ return -1;
+
+ return 0;
+}
+
diff --git a/libc/bionic/ether_aton.c b/libc/bionic/ether_aton.c
new file mode 100644
index 0000000..6540c07
--- /dev/null
+++ b/libc/bionic/ether_aton.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2010 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 <stdlib.h>
+#include <sys/types.h>
+#include <net/if_ether.h>
+#include <ctype.h>
+
+static inline int
+xdigit (char c) {
+ unsigned d;
+ d = (unsigned)(c-'0');
+ if (d < 10) return (int)d;
+ d = (unsigned)(c-'a');
+ if (d < 6) return (int)(10+d);
+ d = (unsigned)(c-'A');
+ if (d < 6) return (int)(10+d);
+ return -1;
+}
+
+/*
+ * Convert Ethernet address in the standard hex-digits-and-colons to binary
+ * representation.
+ * Re-entrant version (GNU extensions)
+ */
+struct ether_addr *
+ether_aton_r (const char *asc, struct ether_addr * addr)
+{
+ int i, val0, val1;
+ for (i = 0; i < ETHER_ADDR_LEN; ++i) {
+ val0 = xdigit(*asc);
+ asc++;
+ if (val0 < 0)
+ return NULL;
+
+ val1 = xdigit(*asc);
+ asc++;
+ if (val1 < 0)
+ return NULL;
+
+ addr->ether_addr_octet[i] = (u_int8_t)((val0 << 4) + val1);
+
+ if (i < ETHER_ADDR_LEN - 1) {
+ if (*asc != ':')
+ return NULL;
+ asc++;
+ }
+ }
+ if (*asc != '\0')
+ return NULL;
+ return addr;
+}
+
+/*
+ * Convert Ethernet address in the standard hex-digits-and-colons to binary
+ * representation.
+ */
+struct ether_addr *
+ether_aton (const char *asc)
+{
+ static struct ether_addr addr;
+ return ether_aton_r(asc, &addr);
+}
diff --git a/libc/bionic/ether_ntoa.c b/libc/bionic/ether_ntoa.c
new file mode 100644
index 0000000..f56e48b
--- /dev/null
+++ b/libc/bionic/ether_ntoa.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2010 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 <sys/types.h>
+#include <net/if_ether.h>
+
+/*
+ * Convert Ethernet address to standard hex-digits-and-colons printable form.
+ * Re-entrant version (GNU extensions).
+ */
+char *
+ether_ntoa_r (const struct ether_addr *addr, char * buf)
+{
+ snprintf(buf, 18, "%02x:%02x:%02x:%02x:%02x:%02x",
+ addr->ether_addr_octet[0], addr->ether_addr_octet[1],
+ addr->ether_addr_octet[2], addr->ether_addr_octet[3],
+ addr->ether_addr_octet[4], addr->ether_addr_octet[5]);
+ return buf;
+}
+
+/*
+ * Convert Ethernet address to standard hex-digits-and-colons printable form.
+ */
+char *
+ether_ntoa (const struct ether_addr *addr)
+{
+ static char buf[18];
+ return ether_ntoa_r(addr, buf);
+}
diff --git a/libc/bionic/eventfd.c b/libc/bionic/eventfd.c
new file mode 100644
index 0000000..fc7a6b9
--- /dev/null
+++ b/libc/bionic/eventfd.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2010 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 <sys/eventfd.h>
+#include <unistd.h>
+
+/* We duplicate the GLibc error semantics, which are poorly defined
+ * if the read() or write() does not return the proper number of bytes.
+ */
+int eventfd_read(int fd, eventfd_t *counter)
+{
+ int ret = read(fd, counter, sizeof(*counter));
+
+ if (ret == sizeof(*counter))
+ return 0;
+
+ return -1;
+}
+
+int eventfd_write(int fd, eventfd_t counter)
+{
+ int ret = write(fd, &counter, sizeof(counter));
+
+ if (ret == sizeof(counter))
+ return 0;
+
+ return -1;
+}
diff --git a/libc/bionic/fcntl.c b/libc/bionic/fcntl.c
new file mode 100644
index 0000000..b49db0a
--- /dev/null
+++ b/libc/bionic/fcntl.c
@@ -0,0 +1,43 @@
+/*
+ * 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 <stdarg.h>
+#include <errno.h>
+
+extern int __fcntl64(int, int, void *);
+
+int fcntl(int fd, int cmd, ...)
+{
+ va_list ap;
+ void * arg;
+
+ va_start(ap, cmd);
+ arg = va_arg(ap, void *);
+ va_end(ap);
+
+ return __fcntl64(fd, cmd, arg);
+}
diff --git a/libc/bionic/flockfile.c b/libc/bionic/flockfile.c
new file mode 100644
index 0000000..368fb15
--- /dev/null
+++ b/libc/bionic/flockfile.c
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+/* implement flockfile(), ftrylockfile() and funlockfile()
+ *
+ * we can't use the OpenBSD implementation which uses kernel-specific
+ * APIs not available on Linux.
+ *
+ * Instead, we use a pthread_mutex_t within the FILE* internal state.
+ * See fileext.h for details.
+ *
+ * the behaviour, if fclose() is called while the corresponding
+ * file is locked is totally undefined.
+ */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include "fileext.h"
+
+
+void
+flockfile(FILE * fp)
+{
+ if (fp != NULL) {
+ _FLOCK_LOCK(fp);
+ }
+}
+
+
+int
+ftrylockfile(FILE *fp)
+{
+ /* The specification for ftrylockfile() says it returns 0 on success,
+ * or non-zero on error. So return an errno code directly on error.
+ */
+ int ret = EINVAL;
+
+ if (fp != NULL) {
+ ret = _FLOCK_TRYLOCK(fp);
+ }
+ return ret;
+}
+
+void
+funlockfile(FILE * fp)
+{
+ if (fp != NULL) {
+ _FLOCK_UNLOCK(fp);
+ }
+}
diff --git a/libc/bionic/fstatfs.c b/libc/bionic/fstatfs.c
new file mode 100644
index 0000000..3d7c696
--- /dev/null
+++ b/libc/bionic/fstatfs.c
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2010 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 <sys/vfs.h>
+
+extern int __fstatfs64(int, size_t, struct statfs *);
+
+int fstatfs(int fd, struct statfs* stat)
+{
+ return __fstatfs64(fd, sizeof(struct statfs), stat);
+}
diff --git a/libc/bionic/ftime.c b/libc/bionic/ftime.c
new file mode 100644
index 0000000..6513593
--- /dev/null
+++ b/libc/bionic/ftime.c
@@ -0,0 +1,49 @@
+/*
+ * 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 <sys/timeb.h>
+
+int ftime(struct timeb *tb)
+{
+ struct timeval tv;
+ struct timezone tz;
+
+ if (gettimeofday (&tv, &tz) < 0)
+ return -1;
+
+ tb->time = tv.tv_sec;
+ tb->millitm = (tv.tv_usec + 500) / 1000;
+
+ if (tb->millitm == 1000) {
+ ++tb->time;
+ tb->millitm = 0;
+ }
+ tb->timezone = tz.tz_minuteswest;
+ tb->dstflag = tz.tz_dsttime;
+
+ return 0;
+}
diff --git a/libc/bionic/ftok.c b/libc/bionic/ftok.c
new file mode 100644
index 0000000..638bd0a
--- /dev/null
+++ b/libc/bionic/ftok.c
@@ -0,0 +1,40 @@
+/*
+ * 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 <unistd.h>
+#include <sys/ipc.h>
+#include <sys/stat.h>
+
+key_t ftok(const char* path, int id)
+{
+ struct stat st;
+
+ if ( lstat(path, &st) < 0 )
+ return -1;
+
+ return (key_t)( (st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16) | ((id & 255) << 24) );
+}
diff --git a/libc/bionic/getdtablesize.c b/libc/bionic/getdtablesize.c
new file mode 100644
index 0000000..91315a5
--- /dev/null
+++ b/libc/bionic/getdtablesize.c
@@ -0,0 +1,39 @@
+/*
+ * 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 <sys/resource.h>
+#include <sys/sysconf.h>
+
+int getdtablesize()
+{
+ struct rlimit r;
+
+ if (getrlimit(RLIMIT_NOFILE, &r) < 0) {
+ return sysconf(_SC_OPEN_MAX);
+ }
+ return r.rlim_cur;
+}
diff --git a/libc/bionic/gethostname.c b/libc/bionic/gethostname.c
new file mode 100644
index 0000000..5d3d7d9
--- /dev/null
+++ b/libc/bionic/gethostname.c
@@ -0,0 +1,51 @@
+/*
+ * 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 <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/utsname.h>
+
+int gethostname(char* buff, size_t buflen)
+{
+ struct utsname name;
+ int result = 0;
+
+ result = uname(&name);
+ if (result != -1)
+ {
+ int namelen = strlen(name.nodename);
+
+ if ((int)buflen < namelen+1) {
+ errno = EINVAL;
+ result = -1;
+ } else {
+ memcpy( buff, name.nodename, namelen+1 );
+ }
+ }
+ return result;
+}
diff --git a/libc/bionic/getpgrp.c b/libc/bionic/getpgrp.c
new file mode 100644
index 0000000..af7ced5
--- /dev/null
+++ b/libc/bionic/getpgrp.c
@@ -0,0 +1,33 @@
+/*
+ * 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 <unistd.h>
+
+pid_t getpgrp(void)
+{
+ return getpgid(0);
+}
diff --git a/libc/bionic/getpriority.c b/libc/bionic/getpriority.c
new file mode 100644
index 0000000..efc9d4e
--- /dev/null
+++ b/libc/bionic/getpriority.c
@@ -0,0 +1,37 @@
+/*
+ * 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 <sys/resource.h>
+
+extern int __getpriority(int, int);
+
+int getpriority(int which, int who)
+{
+ int result = __getpriority(which, who);
+
+ return ( result < 0 ) ? result : 20-result;
+}
diff --git a/libc/bionic/getpt.c b/libc/bionic/getpt.c
new file mode 100644
index 0000000..8bb5c11
--- /dev/null
+++ b/libc/bionic/getpt.c
@@ -0,0 +1,34 @@
+/*
+ * 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 <unistd.h>
+#include <fcntl.h>
+
+int getpt(void)
+{
+ return open("/dev/ptmx", O_RDWR|O_NOCTTY);
+}
diff --git a/libc/bionic/initgroups.c b/libc/bionic/initgroups.c
new file mode 100644
index 0000000..dea6d96
--- /dev/null
+++ b/libc/bionic/initgroups.c
@@ -0,0 +1,58 @@
+/*
+ * 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 <grp.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#define INIT_GROUPS 2
+
+int
+initgroups (const char *user, gid_t group)
+{
+ gid_t groups0[ INIT_GROUPS ];
+ gid_t* groups = groups0;
+ int ret = -1;
+ int numgroups = INIT_GROUPS;
+
+ if (getgrouplist(user, group, groups, &numgroups) < 0) {
+ groups = malloc(numgroups*sizeof(groups[0]));
+ if (groups == NULL)
+ return -1;
+ if (getgrouplist(user,group,groups,&numgroups) < 0) {
+ goto EXIT;
+ }
+ }
+
+ ret = setgroups(numgroups, groups);
+
+EXIT:
+ if (groups != groups0)
+ free(groups);
+
+ return ret;
+}
diff --git a/libc/bionic/isatty.c b/libc/bionic/isatty.c
new file mode 100644
index 0000000..93af6c5
--- /dev/null
+++ b/libc/bionic/isatty.c
@@ -0,0 +1,39 @@
+/*
+ * 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 <unistd.h>
+#include <termios.h>
+#include <errno.h>
+
+int
+isatty (int fd)
+{
+ struct termios term;
+
+ return tcgetattr (fd, &term) == 0;
+}
diff --git a/libc/bionic/issetugid.c b/libc/bionic/issetugid.c
new file mode 100644
index 0000000..81f8e41
--- /dev/null
+++ b/libc/bionic/issetugid.c
@@ -0,0 +1,35 @@
+/*
+ * 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 <unistd.h>
+
+int issetugid(void)
+{
+ /* for Bionic, this is sufficient */
+ return 0;
+}
+
diff --git a/libc/bionic/locale.c b/libc/bionic/locale.c
new file mode 100644
index 0000000..9dabbe4
--- /dev/null
+++ b/libc/bionic/locale.c
@@ -0,0 +1,34 @@
+/*
+ * 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 <locale.h>
+
+char* setlocale (int category, char const *locale)
+{
+ /* INTENTIONAL: there is no locale support in Bionic */
+ return 0;
+}
diff --git a/libc/bionic/lseek64.c b/libc/bionic/lseek64.c
new file mode 100644
index 0000000..db0c413
--- /dev/null
+++ b/libc/bionic/lseek64.c
@@ -0,0 +1,40 @@
+/*
+ * 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 <unistd.h>
+
+extern int __llseek(int fd, unsigned long offset_hi, unsigned long offset_lo, loff_t* result, int whence);
+
+off64_t lseek64(int fd, off64_t off, int whence)
+{
+ loff_t result;
+
+ if ( __llseek(fd, (unsigned long)(off >> 32),(unsigned long)(off), &result, whence ) < 0 )
+ return -1;
+
+ return result;
+}
diff --git a/libc/bionic/memccpy.c b/libc/bionic/memccpy.c
new file mode 100644
index 0000000..789fde6
--- /dev/null
+++ b/libc/bionic/memccpy.c
@@ -0,0 +1,47 @@
+/*
+ * 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/bionic/memchr.c b/libc/bionic/memchr.c
new file mode 100644
index 0000000..b14167a
--- /dev/null
+++ b/libc/bionic/memchr.c
@@ -0,0 +1,46 @@
+/*
+ * 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/bionic/memcmp.c b/libc/bionic/memcmp.c
new file mode 100644
index 0000000..8640954
--- /dev/null
+++ b/libc/bionic/memcmp.c
@@ -0,0 +1,51 @@
+/*
+ * 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/bionic/memcpy.c b/libc/bionic/memcpy.c
new file mode 100644
index 0000000..dea78b2
--- /dev/null
+++ b/libc/bionic/memcpy.c
@@ -0,0 +1,29 @@
+/*
+ * 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/bionic/memmem.c b/libc/bionic/memmem.c
new file mode 100644
index 0000000..e72501b
--- /dev/null
+++ b/libc/bionic/memmem.c
@@ -0,0 +1,64 @@
+/*
+ * 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/bionic/memmove.c b/libc/bionic/memmove.c
new file mode 100644
index 0000000..a9fc1b5
--- /dev/null
+++ b/libc/bionic/memmove.c
@@ -0,0 +1,46 @@
+/*
+ * 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/bionic/memrchr.c b/libc/bionic/memrchr.c
new file mode 100644
index 0000000..aeb5643
--- /dev/null
+++ b/libc/bionic/memrchr.c
@@ -0,0 +1,47 @@
+/*
+ * 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/bionic/memset.c b/libc/bionic/memset.c
new file mode 100644
index 0000000..41dafb2
--- /dev/null
+++ b/libc/bionic/memset.c
@@ -0,0 +1,44 @@
+/*
+ * 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/bionic/memswap.c b/libc/bionic/memswap.c
new file mode 100644
index 0000000..35b0b32
--- /dev/null
+++ b/libc/bionic/memswap.c
@@ -0,0 +1,43 @@
+/*
+ * 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/bionic/mmap.c b/libc/bionic/mmap.c
new file mode 100644
index 0000000..e097086
--- /dev/null
+++ b/libc/bionic/mmap.c
@@ -0,0 +1,50 @@
+/*
+ * 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 <unistd.h>
+#include <errno.h>
+#include <sys/mman.h>
+
+extern void* __mmap2(void*, size_t, int, int, int, size_t);
+
+#define MMAP2_SHIFT 12
+void* mmap(void *addr, size_t size, int prot, int flags, int fd, long offset)
+{
+ void *ret;
+
+ if (offset & ((1UL << MMAP2_SHIFT)-1)) {
+ errno = EINVAL;
+ return MAP_FAILED;
+ }
+
+ ret = __mmap2(addr, size, prot, flags, fd, (size_t)offset >> MMAP2_SHIFT);
+
+ if (ret && (flags & (MAP_PRIVATE | MAP_ANONYMOUS)))
+ madvise(ret, size, MADV_MERGEABLE);
+
+ return ret;
+}
diff --git a/libc/bionic/open.c b/libc/bionic/open.c
new file mode 100644
index 0000000..56602db
--- /dev/null
+++ b/libc/bionic/open.c
@@ -0,0 +1,65 @@
+/*
+ * 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 <unistd.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <private/logd.h>
+
+extern int __open(const char*, int, int);
+
+int open(const char *pathname, int flags, ...)
+{
+ mode_t mode = 0;
+
+ flags |= O_LARGEFILE;
+
+ if (flags & O_CREAT)
+ {
+ va_list args;
+
+ va_start(args, flags);
+ mode = (mode_t) va_arg(args, int);
+ va_end(args);
+ }
+
+ return __open(pathname, flags, mode);
+}
+
+int __open_2(const char *pathname, int flags) {
+ if (flags & O_CREAT) {
+ __libc_android_log_print(ANDROID_LOG_FATAL, "libc",
+ "*** open(O_CREAT) called without specifying a mode ***\n");
+ abort();
+ }
+
+ flags |= O_LARGEFILE;
+
+ return __open(pathname, flags, 0);
+}
+
diff --git a/libc/bionic/openat.c b/libc/bionic/openat.c
new file mode 100644
index 0000000..fb04e9c
--- /dev/null
+++ b/libc/bionic/openat.c
@@ -0,0 +1,66 @@
+/*
+ * 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 <unistd.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <private/logd.h>
+
+extern int __openat(int, const char*, int, int);
+
+int openat(int fd, const char *pathname, int flags, ...)
+{
+ mode_t mode = 0;
+
+ flags |= O_LARGEFILE;
+
+ if (flags & O_CREAT)
+ {
+ va_list args;
+
+ va_start(args, flags);
+ mode = (mode_t) va_arg(args, int);
+ va_end(args);
+ }
+
+ return __openat(fd, pathname, flags, mode);
+}
+
+int __openat_2(int fd, const char *pathname, int flags)
+{
+ if (flags & O_CREAT) {
+ __libc_android_log_print(ANDROID_LOG_FATAL, "libc",
+ "*** openat(O_CREAT) called without specifying a mode ***\n");
+ abort();
+ }
+
+ flags |= O_LARGEFILE;
+
+ return __openat(fd, pathname, flags, 0);
+}
+
diff --git a/libc/bionic/opendir.c b/libc/bionic/opendir.c
new file mode 100644
index 0000000..f178bc6
--- /dev/null
+++ b/libc/bionic/opendir.c
@@ -0,0 +1,273 @@
+/*
+ * 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 <unistd.h>
+#include <dirent.h>
+#include <memory.h>
+#include <string.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <errno.h>
+
+struct DIR
+{
+ int _DIR_fd;
+ size_t _DIR_avail;
+ struct dirent* _DIR_next;
+ pthread_mutex_t _DIR_lock;
+ struct dirent _DIR_buff[15];
+};
+
+int dirfd(DIR* dirp)
+{
+ return dirp->_DIR_fd;
+}
+
+DIR* opendir( const char* dirpath )
+{
+ DIR* dir = malloc(sizeof(DIR));
+
+ if (!dir)
+ goto Exit;
+
+ dir->_DIR_fd = open(dirpath, O_RDONLY|O_DIRECTORY);
+ if (dir->_DIR_fd < 0)
+ {
+ free(dir);
+ dir = NULL;
+ }
+ else
+ {
+ dir->_DIR_avail = 0;
+ dir->_DIR_next = NULL;
+ pthread_mutex_init( &dir->_DIR_lock, NULL );
+ }
+Exit:
+ return dir;
+}
+
+
+DIR* fdopendir(int fd)
+{
+ DIR* dir = malloc(sizeof(DIR));
+
+ if (!dir)
+ return 0;
+
+ dir->_DIR_fd = fd;
+ dir->_DIR_avail = 0;
+ dir->_DIR_next = NULL;
+ pthread_mutex_init( &dir->_DIR_lock, NULL );
+
+ return dir;
+}
+
+
+static struct dirent*
+_readdir_unlocked(DIR* dir)
+{
+ struct dirent* entry;
+#ifndef NDEBUG
+ unsigned reclen;
+#endif
+
+ if ( !dir->_DIR_avail )
+ {
+ int rc;
+
+ for (;;) {
+ rc = getdents( dir->_DIR_fd, dir->_DIR_buff, sizeof(dir->_DIR_buff));
+ if (rc >= 0 || errno != EINTR)
+ break;
+ }
+ if (rc <= 0)
+ return NULL;
+
+ dir->_DIR_avail = rc;
+ dir->_DIR_next = dir->_DIR_buff;
+ }
+
+ entry = dir->_DIR_next;
+
+ /* perform some sanity checks here */
+ if (((long)(void*)entry & 3) != 0)
+ return NULL;
+
+#ifndef NDEBUG
+ // paranoid testing of the interface with the kernel getdents64 system call
+ reclen = offsetof(struct dirent, d_name) + strlen(entry->d_name) + 1;
+ if ( reclen > sizeof(*entry) || reclen <= offsetof(struct dirent, d_name) )
+ goto Bad;
+
+ if ( (char*)entry + reclen > (char*)dir->_DIR_buff + sizeof(dir->_DIR_buff) )
+ goto Bad;
+
+ if ( !memchr( entry->d_name, 0, reclen - offsetof(struct dirent, d_name)) )
+ goto Bad;
+#endif
+
+ dir->_DIR_next = (struct dirent*)((char*)entry + entry->d_reclen);
+ dir->_DIR_avail -= entry->d_reclen;
+
+ return entry;
+
+ Bad:
+ errno = EINVAL;
+ return NULL;
+}
+
+
+struct dirent*
+readdir(DIR * dir)
+{
+ struct dirent *entry = NULL;
+
+ pthread_mutex_lock( &dir->_DIR_lock );
+ entry = _readdir_unlocked(dir);
+ pthread_mutex_unlock( &dir->_DIR_lock );
+
+ return entry;
+}
+
+
+int readdir_r(DIR* dir, struct dirent *entry, struct dirent **result)
+{
+ struct dirent* ent;
+ int save_errno = errno;
+ int retval;
+
+ *result = NULL;
+ errno = 0;
+
+ pthread_mutex_lock( &dir->_DIR_lock );
+
+ ent = _readdir_unlocked(dir);
+ retval = errno;
+ if (ent == NULL) {
+ if (!retval) {
+ errno = save_errno;
+ }
+ } else {
+ if (!retval) {
+ errno = save_errno;
+ *result = entry;
+ memcpy( entry, ent, ent->d_reclen );
+ }
+ }
+
+ pthread_mutex_unlock( &dir->_DIR_lock );
+
+ return retval;
+}
+
+
+
+int closedir(DIR *dir)
+{
+ int rc;
+
+ rc = close(dir->_DIR_fd);
+ dir->_DIR_fd = -1;
+
+ pthread_mutex_destroy( &dir->_DIR_lock );
+
+ free(dir);
+ return rc;
+}
+
+
+void rewinddir(DIR *dir)
+{
+ pthread_mutex_lock( &dir->_DIR_lock );
+ lseek( dir->_DIR_fd, 0, SEEK_SET );
+ dir->_DIR_avail = 0;
+ pthread_mutex_unlock( &dir->_DIR_lock );
+}
+
+
+int alphasort(const void *a, const void *b)
+{
+ struct dirent **d1, **d2;
+
+ d1 = (struct dirent **) a;
+ d2 = (struct dirent **) b;
+ return strcmp((*d1)->d_name, (*d2)->d_name);
+}
+
+
+int scandir(const char *dir, struct dirent ***namelist,
+ int(*filter)(const struct dirent *),
+ int(*compar)(const struct dirent **, const struct dirent **))
+{
+ DIR *d;
+ int n_elem = 0;
+ struct dirent *this_de, *de;
+ struct dirent **de_list = NULL;
+ int de_list_size = 0;
+
+ d = opendir(dir);
+ if (d == NULL) {
+ return -1;
+ }
+
+ while ((this_de = readdir(d)) != NULL) {
+ if (filter && (*filter)(this_de) == 0) {
+ continue;
+ }
+ if (n_elem == 0) {
+ de_list_size = 4;
+ de_list = (struct dirent **)
+ malloc(sizeof(struct dirent *)*de_list_size);
+ if (de_list == NULL) {
+ return -1;
+ }
+ }
+ else if (n_elem == de_list_size) {
+ struct dirent **de_list_new;
+
+ de_list_size += 10;
+ de_list_new = (struct dirent **)
+ realloc(de_list, sizeof(struct dirent *)*de_list_size);
+ if (de_list_new == NULL) {
+ free(de_list);
+ return -1;
+ }
+ de_list = de_list_new;
+ }
+ de = (struct dirent *) malloc(sizeof(struct dirent));
+ *de = *this_de;
+ de_list[n_elem++] = de;
+ }
+ closedir(d);
+ if (n_elem && compar) {
+ qsort(de_list, n_elem, sizeof(struct dirent *),
+ (int (*)(const void *, const void *)) compar);
+ }
+ *namelist = de_list;
+ return n_elem;
+}
diff --git a/libc/bionic/pathconf.c b/libc/bionic/pathconf.c
new file mode 100644
index 0000000..26b580f
--- /dev/null
+++ b/libc/bionic/pathconf.c
@@ -0,0 +1,270 @@
+/*
+ * 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 <pathconf.h>
+#include <sys/vfs.h>
+#include <sys/limits.h>
+#include <linux/ext2_fs.h>
+#include <linux/ext3_fs.h>
+#include <errno.h>
+
+/* these may not be defined yet by our headers */
+#ifndef _POSIX_VDISABLE
+#define _POSIX_VDISABLE -1
+#endif
+
+#ifndef _POSIX_SYNC_IO
+#define _POSIX_SYNC_IO -1
+#endif
+
+#ifndef _POSIX_PRIO_IO
+#define _POSIX_PRIO_IO -1
+#endif
+
+#ifndef _POSIX_ASYNC_IO
+#define _POSIX_ASYNC_IO -1
+#endif
+
+
+static long
+__filesizebits( struct statfs* s )
+{
+#define EOL_MAGIC 0x0000U
+
+ /* list of known 64-bit aware filesystems */
+ static const uint32_t known64[] = {
+ EXT2_SUPER_MAGIC,
+ UFS_MAGIC,
+ REISERFS_SUPER_MAGIC,
+ XFS_SUPER_MAGIC,
+ SMB_SUPER_MAGIC,
+ UDF_SUPER_MAGIC,
+ JFS_SUPER_MAGIC,
+ NTFS_SB_MAGIC,
+ VXFS_SUPER_MAGIC,
+ EOL_MAGIC
+ };
+ int nn = 0;
+
+ for (; known64[nn] != EOL_MAGIC; ++nn) {
+ if (known64[nn] == s->f_type) {
+ return 64;
+ }
+ }
+ return 32;
+}
+
+
+static long
+__link_max( struct statfs* s )
+{
+ /* constant values were taken from official kernel headers.
+ * I don't think this justified bringing in <linux/minix_fs.h> et al
+ * into our cleaned-up kernel three
+ */
+ static const struct { uint32_t type; int max; } knownMax[] =
+ {
+ { EXT2_SUPER_MAGIC, EXT2_LINK_MAX },
+ { EXT3_SUPER_MAGIC, EXT3_LINK_MAX },
+ { MINIX_SUPER_MAGIC, 250 },
+ { MINIX2_SUPER_MAGIC, 65530 },
+ { REISERFS_SUPER_MAGIC, 0xffff - 1000 },
+ { UFS_MAGIC, 32000 },
+ { EOL_MAGIC, 0 }
+ };
+ int nn = 0;
+
+ for (; knownMax[nn].type != EOL_MAGIC; ++nn) {
+ if (knownMax[nn].type == s->f_type) {
+ return knownMax[nn].max;
+ }
+ }
+ return LINK_MAX;
+}
+
+static long
+__2_symlinks( struct statfs* s )
+{
+ /* list of know filesystems that don't support symlinks */
+ static const uint32_t knownNoSymlinks[] = {
+ ADFS_SUPER_MAGIC, BFS_MAGIC, CRAMFS_MAGIC,
+ EFS_SUPER_MAGIC, MSDOS_SUPER_MAGIC, NTFS_SB_MAGIC,
+ QNX4_SUPER_MAGIC,
+ EOL_MAGIC
+ };
+ int nn = 0;
+
+ for (; knownNoSymlinks[nn] != EOL_MAGIC; ++nn) {
+ if (knownNoSymlinks[nn] == s->f_type) {
+ return 0;
+ }
+ }
+ return 1;
+}
+
+static long
+__name_max( struct statfs* s )
+{
+ return s->f_namelen;
+}
+
+long
+pathconf(const char *path, int name)
+{
+ struct statfs buf;
+ int ret = statfs( path, &buf );
+
+ if (ret < 0)
+ return -1;
+
+ switch (name) {
+ case _PC_FILESIZEBITS:
+ return __filesizebits(&buf);
+
+ case _PC_LINK_MAX:
+ return __link_max(&buf);
+
+ case _PC_MAX_CANON:
+ return MAX_CANON;
+
+ case _PC_MAX_INPUT:
+ return MAX_INPUT;
+
+ case _PC_NAME_MAX:
+ return __name_max(&buf);
+
+ case _PC_PATH_MAX:
+ return PATH_MAX;
+
+ case _PC_PIPE_BUF:
+ return PIPE_BUF;
+
+ case _PC_2_SYMLINKS:
+ return __2_symlinks(&buf);
+
+#if 0 /* don't know what to do there, the specs are really weird */
+ case _PC_ALLOC_SIZE_MIN:
+ case _PC_REC_INCR_XFER_SIZE:
+ case _PC_REC_MAX_XFER_SIZE:
+ case _PC_REC_MIN_XFER_SIZE:
+ case _PC_REC_XFER_ALIGN:
+#endif
+
+ case _PC_SYMLINK_MAX:
+ return -1; /* no limit */
+
+ case _PC_CHOWN_RESTRICTED:
+ return _POSIX_CHOWN_RESTRICTED;
+
+ case _PC_NO_TRUNC:
+ return _POSIX_NO_TRUNC;
+
+ case _PC_VDISABLE:
+ return _POSIX_VDISABLE;
+
+ case _PC_ASYNC_IO:
+ return _POSIX_ASYNC_IO;
+
+ case _PC_PRIO_IO:
+ return _POSIX_PRIO_IO;
+
+ case _PC_SYNC_IO:
+ return _POSIX_SYNC_IO;
+
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+}
+
+long fpathconf(int fildes, int name)
+{
+ struct statfs buf;
+ int ret = fstatfs(fildes, &buf);
+
+ if (ret < 0)
+ return -1;
+
+ switch (name) {
+ case _PC_FILESIZEBITS:
+ return __filesizebits(&buf);
+
+ case _PC_LINK_MAX:
+ return __link_max(&buf);
+
+ case _PC_MAX_CANON:
+ return MAX_CANON;
+
+ case _PC_MAX_INPUT:
+ return MAX_INPUT;
+
+ case _PC_NAME_MAX:
+ return __name_max(&buf);
+
+ case _PC_PATH_MAX:
+ return PATH_MAX;
+
+ case _PC_PIPE_BUF:
+ return PIPE_BUF;
+
+ case _PC_2_SYMLINKS:
+ return __2_symlinks(&buf);
+
+#if 0 /* don't know what to do there, the specs are really weird */
+ case _PC_ALLOC_SIZE_MIN:
+ case _PC_REC_INCR_XFER_SIZE:
+ case _PC_REC_MAX_XFER_SIZE:
+ case _PC_REC_MIN_XFER_SIZE:
+ case _PC_REC_XFER_ALIGN:
+#endif
+
+ case _PC_SYMLINK_MAX:
+ return -1; /* no limit */
+
+ case _PC_CHOWN_RESTRICTED:
+ return _POSIX_CHOWN_RESTRICTED;
+
+ case _PC_NO_TRUNC:
+ return _POSIX_NO_TRUNC;
+
+ case _PC_VDISABLE:
+ return _POSIX_VDISABLE;
+
+ case _PC_ASYNC_IO:
+ return _POSIX_ASYNC_IO;
+
+ case _PC_PRIO_IO:
+ return _POSIX_PRIO_IO;
+
+ case _PC_SYNC_IO:
+ return _POSIX_SYNC_IO;
+
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+}
diff --git a/libc/bionic/perror.c b/libc/bionic/perror.c
new file mode 100644
index 0000000..de55f72
--- /dev/null
+++ b/libc/bionic/perror.c
@@ -0,0 +1,44 @@
+/*
+ * 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 <errno.h>
+#include <unistd.h>
+#include <string.h>
+
+void perror(const char *prefix)
+{
+ char buff[256];
+
+ strerror_r( errno, buff, sizeof(buff) );
+
+ if (prefix) {
+ write( 2, prefix, strlen(prefix) );
+ write( 2, ": ", 2 );
+ }
+ write( 2, buff, strlen(buff) );
+ write( 2, "\n", 1 );
+}
diff --git a/libc/bionic/pread.c b/libc/bionic/pread.c
new file mode 100644
index 0000000..42fc3bc
--- /dev/null
+++ b/libc/bionic/pread.c
@@ -0,0 +1,35 @@
+/*
+ * 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 <sys/types.h>
+#include <unistd.h>
+
+ssize_t pread(int fd, void *buf, size_t nbytes, off_t offset)
+{
+ return pread64(fd, buf, nbytes, (off64_t)offset);
+}
+
diff --git a/libc/bionic/pselect.c b/libc/bionic/pselect.c
new file mode 100644
index 0000000..76ce2c0
--- /dev/null
+++ b/libc/bionic/pselect.c
@@ -0,0 +1,59 @@
+/*
+ * 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 <sys/select.h>
+#include <signal.h>
+#include <pthread.h>
+
+int
+pselect(int n, fd_set* readfds, fd_set* writefds, fd_set* errfds,
+ const struct timespec* timeout, const sigset_t* sigmask)
+{
+ sigset_t oldmask;
+ int result;
+ struct timeval tv, *tv_timeout = NULL;
+
+ if (sigmask != NULL)
+ pthread_sigmask( SIG_SETMASK, sigmask, &oldmask );
+
+ if (timeout != NULL) {
+ tv_timeout = &tv;
+ tv.tv_sec = timeout->tv_sec;
+ tv.tv_usec = (timeout->tv_nsec + 999)/1000; // round up
+ if (tv.tv_usec >= 1000000) {
+ tv.tv_sec += 1;
+ tv.tv_usec -= 1000000;
+ }
+ }
+
+ result = select( n, readfds, writefds, errfds, tv_timeout );
+
+ if (sigmask != NULL)
+ pthread_sigmask( SIG_SETMASK, &oldmask, NULL );
+
+ return result;
+}
diff --git a/libc/bionic/ptsname.c b/libc/bionic/ptsname.c
new file mode 100644
index 0000000..24d5d30
--- /dev/null
+++ b/libc/bionic/ptsname.c
@@ -0,0 +1,44 @@
+/*
+ * 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 <stdio.h>
+#include <unistd.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+
+/* not thread-safe */
+char* ptsname( int fd )
+{
+ unsigned int pty_num;
+ static char buff[64];
+
+ if ( ioctl( fd, TIOCGPTN, &pty_num ) != 0 )
+ return NULL;
+
+ snprintf( buff, sizeof(buff), "/dev/pts/%u", pty_num );
+ return buff;
+}
diff --git a/libc/bionic/ptsname_r.c b/libc/bionic/ptsname_r.c
new file mode 100644
index 0000000..2fa4c3d
--- /dev/null
+++ b/libc/bionic/ptsname_r.c
@@ -0,0 +1,58 @@
+/*
+ * 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 <stdio.h>
+#include <unistd.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <string.h>
+
+int ptsname_r( int fd, char* buf, size_t buflen)
+{
+ unsigned int pty_num;
+ char buff[64];
+ int len;
+
+ if (buf == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if ( ioctl( fd, TIOCGPTN, &pty_num ) != 0 ) {
+ errno = ENOTTY;
+ return -1;
+ }
+
+ len = snprintf( buff, sizeof(buff), "/dev/pts/%u", pty_num );
+ if (len+1 > (int)buflen) {
+ errno = ERANGE;
+ return -1;
+ }
+ memcpy( buf, buff, len+1 );
+ return 0;
+}
diff --git a/libc/bionic/pwrite.c b/libc/bionic/pwrite.c
new file mode 100644
index 0000000..f106cb3
--- /dev/null
+++ b/libc/bionic/pwrite.c
@@ -0,0 +1,35 @@
+/*
+ * 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 <sys/types.h>
+#include <unistd.h>
+
+ssize_t pwrite(int fd, const void *buf, size_t nbytes, off_t offset)
+{
+ return pwrite64(fd, buf, nbytes, (off64_t)offset);
+}
+
diff --git a/libc/bionic/raise.c b/libc/bionic/raise.c
new file mode 100644
index 0000000..7b03a7a
--- /dev/null
+++ b/libc/bionic/raise.c
@@ -0,0 +1,34 @@
+/*
+ * 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 <unistd.h>
+#include <signal.h>
+
+int raise(int signum)
+{
+ return kill(gettid(), signum);
+}
diff --git a/libc/bionic/reboot.c b/libc/bionic/reboot.c
new file mode 100644
index 0000000..0fe8cdc
--- /dev/null
+++ b/libc/bionic/reboot.c
@@ -0,0 +1,34 @@
+/*
+ * 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 <unistd.h>
+#include <sys/reboot.h>
+
+int reboot (int mode)
+{
+ return __reboot( LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, mode, NULL );
+}
diff --git a/libc/bionic/recv.c b/libc/bionic/recv.c
new file mode 100644
index 0000000..779d7fa
--- /dev/null
+++ b/libc/bionic/recv.c
@@ -0,0 +1,34 @@
+/*
+ * 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 <sys/socket.h>
+
+ssize_t recv(int socket, void *buf, size_t buflen, unsigned int flags)
+{
+ return recvfrom(socket, buf, buflen, flags, NULL, 0);
+}
diff --git a/libc/bionic/sbrk.c b/libc/bionic/sbrk.c
new file mode 100644
index 0000000..a112b6c
--- /dev/null
+++ b/libc/bionic/sbrk.c
@@ -0,0 +1,60 @@
+/*
+ * 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 <unistd.h>
+#include <errno.h>
+
+
+#define SBRK_ALIGN 32
+
+/* shared with brk() implementation */
+char* __bionic_brk;
+
+void *sbrk(ptrdiff_t increment)
+{
+ char* start;
+ char* end;
+ char* new_brk;
+
+ if ( !__bionic_brk)
+ __bionic_brk = __brk((void*)0);
+
+ start = (char*)(((long)__bionic_brk + SBRK_ALIGN-1) & ~(SBRK_ALIGN-1));
+ end = start + increment;
+
+ new_brk = __brk(end);
+ if (new_brk == (void*)-1)
+ return new_brk;
+ else if (new_brk < end)
+ {
+ errno = ENOMEM;
+ return (void*)-1;
+ }
+
+ __bionic_brk = new_brk;
+ return start;
+}
diff --git a/libc/bionic/send.c b/libc/bionic/send.c
new file mode 100644
index 0000000..9978f98
--- /dev/null
+++ b/libc/bionic/send.c
@@ -0,0 +1,34 @@
+/*
+ * 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 <sys/socket.h>
+
+ssize_t send(int socket, const void *buf, size_t buflen, unsigned int flags)
+{
+ return (ssize_t) sendto(socket, buf, buflen, flags, NULL, 0);
+}
diff --git a/libc/bionic/setegid.c b/libc/bionic/setegid.c
new file mode 100644
index 0000000..9bd697b
--- /dev/null
+++ b/libc/bionic/setegid.c
@@ -0,0 +1,33 @@
+/*
+ * 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 <unistd.h>
+
+int setegid(gid_t egid)
+{
+ return setresgid(-1, egid, -1);
+}
diff --git a/libc/bionic/seteuid.c b/libc/bionic/seteuid.c
new file mode 100644
index 0000000..b3ea372
--- /dev/null
+++ b/libc/bionic/seteuid.c
@@ -0,0 +1,37 @@
+/*
+ * 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 <unistd.h>
+#include "cpuacct.h"
+
+extern int __setresuid(uid_t, uid_t, uid_t);
+
+int seteuid(uid_t euid)
+{
+ cpuacct_add(euid);
+ return __setresuid(-1, euid,-1);
+}
diff --git a/libc/bionic/setpgrp.c b/libc/bionic/setpgrp.c
new file mode 100644
index 0000000..6dff822
--- /dev/null
+++ b/libc/bionic/setpgrp.c
@@ -0,0 +1,33 @@
+/*
+ * 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 <unistd.h>
+
+int setpgrp(void)
+{
+ return setpgid(0,0);
+}
diff --git a/libc/bionic/setresuid.c b/libc/bionic/setresuid.c
new file mode 100644
index 0000000..e62b3e9
--- /dev/null
+++ b/libc/bionic/setresuid.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2010 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 <unistd.h>
+#include "cpuacct.h"
+
+extern int __setresuid(uid_t ruid, uid_t euid, uid_t suid);
+
+int setresuid(uid_t ruid, uid_t euid, uid_t suid)
+{
+ cpuacct_add(euid);
+ return __setresuid(ruid, euid, suid);
+
+}
diff --git a/libc/bionic/setreuid.c b/libc/bionic/setreuid.c
new file mode 100644
index 0000000..32e70c8
--- /dev/null
+++ b/libc/bionic/setreuid.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2010 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 <unistd.h>
+#include "cpuacct.h"
+
+extern int __setreuid(uid_t ruid, uid_t euid);
+
+int setreuid(uid_t ruid, uid_t euid)
+{
+ cpuacct_add(euid);
+ return __setreuid(ruid, euid);
+}
diff --git a/libc/bionic/setuid.c b/libc/bionic/setuid.c
new file mode 100644
index 0000000..30785d6
--- /dev/null
+++ b/libc/bionic/setuid.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2010 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 <unistd.h>
+#include "cpuacct.h"
+
+extern int __setuid(uid_t);
+
+int setuid(uid_t uid)
+{
+ cpuacct_add(uid);
+ return __setuid(uid);
+}
diff --git a/libc/bionic/sigblock.c b/libc/bionic/sigblock.c
new file mode 100644
index 0000000..176bc13
--- /dev/null
+++ b/libc/bionic/sigblock.c
@@ -0,0 +1,50 @@
+/*
+ * 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 <signal.h>
+
+/* this function is called from the ARM assembly setjmp fragments */
+int
+sigblock(int mask)
+{
+ int n;
+ union {
+ int the_mask;
+ sigset_t the_sigset;
+ } in, out;
+
+ sigemptyset(&in.the_sigset);
+ in.the_mask = mask;
+
+ n = sigprocmask(SIG_BLOCK, &in.the_sigset, &out.the_sigset);
+ if (n)
+ return n;
+
+ return out.the_mask;
+}
+
+
diff --git a/libc/bionic/siginterrupt.c b/libc/bionic/siginterrupt.c
new file mode 100644
index 0000000..4e91edb
--- /dev/null
+++ b/libc/bionic/siginterrupt.c
@@ -0,0 +1,45 @@
+/*
+ * 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 <signal.h>
+
+/* this is only useful for legacy programs */
+int siginterrupt(int sig, int flag)
+{
+ struct sigaction act;
+
+ (void) sigaction(sig, NULL, &act);
+
+ if (flag)
+ act.sa_flags &= ~SA_RESTART;
+ else
+ act.sa_flags |= SA_RESTART;
+
+ return sigaction(sig, &act, NULL);
+}
+
diff --git a/libc/bionic/siglist.c b/libc/bionic/siglist.c
new file mode 100644
index 0000000..f1c3377
--- /dev/null
+++ b/libc/bionic/siglist.c
@@ -0,0 +1,33 @@
+/*
+ * 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 <signal.h>
+
+const char * const sys_siglist[NSIG] = {
+#define __BIONIC_SIGDEF(x,y,z) [ SIG##x ] = z,
+#include <sys/_sigdefs.h>
+};
diff --git a/libc/bionic/signal.c b/libc/bionic/signal.c
new file mode 100644
index 0000000..949db13
--- /dev/null
+++ b/libc/bionic/signal.c
@@ -0,0 +1,57 @@
+/*
+ * 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 <signal.h>
+
+
+static __sighandler_t
+_signal(int signum, __sighandler_t handler, int flags)
+{
+ struct sigaction sa;
+ __sighandler_t result = SIG_ERR;
+
+ sigemptyset( &sa.sa_mask );
+
+ sa.sa_handler = handler;
+ sa.sa_flags = flags;
+
+ if ( !sigaction( signum, &sa, &sa ) )
+ result = (__sighandler_t) sa.sa_handler;
+
+ return result;
+}
+
+
+__sighandler_t bsd_signal(int signum, __sighandler_t handler)
+{
+ return _signal(signum, handler, SA_RESTART);
+}
+
+__sighandler_t sysv_signal(int signum, __sighandler_t handler)
+{
+ return _signal(signum, handler, SA_RESETHAND);
+}
diff --git a/libc/bionic/signame.c b/libc/bionic/signame.c
new file mode 100644
index 0000000..4611e44
--- /dev/null
+++ b/libc/bionic/signame.c
@@ -0,0 +1,33 @@
+/*
+ * 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 <signal.h>
+
+const char * const sys_signame[NSIG] = {
+#define __BIONIC_SIGDEF(x,y,z) [ SIG##x ] = #x,
+#include <sys/_sigdefs.h>
+};
diff --git a/libc/bionic/sigsetmask.c b/libc/bionic/sigsetmask.c
new file mode 100644
index 0000000..7842bf1
--- /dev/null
+++ b/libc/bionic/sigsetmask.c
@@ -0,0 +1,50 @@
+/*
+ * 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 <signal.h>
+
+/* called from setjmp assembly fragment */
+int
+sigsetmask(int mask)
+{
+ int n;
+
+ union {
+ int the_mask;
+ sigset_t the_sigset;
+ } in, out;
+
+ sigemptyset(&in.the_sigset);
+ in.the_mask = mask;
+
+ n = sigprocmask(SIG_SETMASK, &in.the_sigset, &out.the_sigset);
+ if (n)
+ return n;
+
+ return out.the_mask;
+}
+
diff --git a/libc/bionic/sigsuspend.c b/libc/bionic/sigsuspend.c
new file mode 100644
index 0000000..fd08631
--- /dev/null
+++ b/libc/bionic/sigsuspend.c
@@ -0,0 +1,43 @@
+/*
+ * 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 <signal.h>
+#ifdef __mips__
+extern int __sigsuspend(const sigset_t *);
+#else
+extern int __sigsuspend(int, int, unsigned int);
+#endif
+
+int sigsuspend(const sigset_t *_mask)
+{
+#ifdef __mips__
+ return __sigsuspend(_mask);
+#else
+ unsigned int mask = (unsigned int)*_mask;
+ return __sigsuspend(0, 0, mask);
+#endif
+}
diff --git a/libc/bionic/sigwait.c b/libc/bionic/sigwait.c
new file mode 100644
index 0000000..1e90c41
--- /dev/null
+++ b/libc/bionic/sigwait.c
@@ -0,0 +1,83 @@
+/*
+ * 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 <errno.h>
+#include <signal.h>
+#include <string.h>
+#include <time.h>
+
+int __rt_sigtimedwait(const sigset_t *uthese, siginfo_t *uinfo, const struct timespec *uts, size_t sigsetsize);
+
+/* ok, this is really subtle: <asm/signal.h> defines sigset_t differently
+ * when you're in the kernel or in the C library.
+ *
+ * in the kernel, this is an array of 2 32-bit unsigned longs
+ * in the C library, this is a single 32-bit unsigned long
+ *
+ * moreover, the kernel implementation of rt_sigtimedwait doesn't
+ * accept anything except kernel-sized signal sets (probably a bug !)
+ *
+ * we thus need to create a fake kernel sigset !!
+ */
+
+int sigwait(const sigset_t *set, int *sig)
+{
+ int ret;
+#ifdef __mips__
+ /* use a union to get rid of aliasing warnings. On MIPS sigset_t is 128 bits */
+ union {
+ sigset_t kernel_sigset;
+ sigset_t dummy_sigset;
+ } u;
+ u.dummy_sigset = *set;
+#else
+ /* use a union to get rid of aliasing warnings */
+ union {
+ unsigned long kernel_sigset[2];
+ sigset_t dummy_sigset;
+ } u;
+
+ u.kernel_sigset[0] = *set;
+ u.kernel_sigset[1] = 0; /* no real-time signals supported ? */
+#endif
+ for (;;)
+ {
+ /* __rt_sigtimedwait can return EAGAIN or EINTR, we need to loop
+ * around them since sigwait is only allowed to return EINVAL
+ */
+ ret = __rt_sigtimedwait ( &u.dummy_sigset, NULL, NULL, sizeof(u.kernel_sigset));
+ if (ret >= 0)
+ break;
+
+ if (errno != EAGAIN && errno != EINTR)
+ return errno;
+ }
+
+ *sig = ret;
+ return 0;
+}
+
diff --git a/libc/bionic/sleep.c b/libc/bionic/sleep.c
new file mode 100644
index 0000000..aafbd60
--- /dev/null
+++ b/libc/bionic/sleep.c
@@ -0,0 +1,52 @@
+/*
+ * 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 <time.h>
+#include <errno.h>
+
+unsigned int sleep(unsigned int seconds)
+{
+ struct timespec t;
+
+ /* seconds is unsigned, while t.tv_sec is signed
+ * some people want to do sleep(UINT_MAX), so fake
+ * support for it by only sleeping 2 billion seconds
+ */
+ if ((int)seconds < 0)
+ seconds = 0x7fffffff;
+
+ t.tv_sec = seconds;
+ t.tv_nsec = 0;
+
+ if ( !nanosleep( &t, &t ) )
+ return 0;
+
+ if ( errno == EINTR )
+ return t.tv_sec;
+
+ return -1;
+}
diff --git a/libc/bionic/socketcalls.c b/libc/bionic/socketcalls.c
new file mode 100644
index 0000000..51bdf57
--- /dev/null
+++ b/libc/bionic/socketcalls.c
@@ -0,0 +1,259 @@
+/*
+ * 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 <unistd.h>
+#include <sys/socket.h>
+#include <sys/linux-syscalls.h>
+
+enum
+{
+ SYS_SOCKET = 1,
+ SYS_BIND,
+ SYS_CONNECT,
+ SYS_LISTEN,
+ SYS_ACCEPT,
+ SYS_GETSOCKNAME,
+ SYS_GETPEERNAME,
+ SYS_SOCKETPAIR,
+ SYS_SEND,
+ SYS_RECV,
+ SYS_SENDTO,
+ SYS_RECVFROM,
+ SYS_SHUTDOWN,
+ SYS_SETSOCKOPT,
+ SYS_GETSOCKOPT,
+ SYS_SENDMSG,
+ SYS_RECVMSG
+};
+
+#ifndef __NR_socket
+int socket(int domain, int type, int protocol)
+{
+ unsigned long t[3];
+
+ t[0] = (unsigned long) domain;
+ t[1] = (unsigned long) type;
+ t[2] = (unsigned long) protocol;
+
+ return (int) __socketcall( SYS_SOCKET, t );
+}
+#endif /* !__NR_socket */
+
+
+#ifndef __NR_bind
+int bind(int sockfd, const struct sockaddr *my_addr, socklen_t addrlen)
+{
+ unsigned long t[3];
+
+ t[0] = (unsigned long) sockfd;
+ t[1] = (unsigned long) my_addr;
+ t[2] = (unsigned long) addrlen;
+
+ return (int) __socketcall( SYS_BIND, t );
+}
+#endif /* !__NR_bind */
+
+#ifndef __NR_connect
+int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen )
+{
+ unsigned long t[3];
+
+ t[0] = (unsigned long) sockfd;
+ t[1] = (unsigned long) serv_addr;
+ t[2] = (unsigned long) addrlen;
+
+ return (int) __socketcall( SYS_CONNECT, t );
+}
+#endif /* !__NR_connect */
+
+#ifndef __NR_listen
+int listen(int s, int backlog)
+{
+ unsigned long t[2];
+
+ t[0] = (unsigned long) s;
+ t[1] = (unsigned long) backlog;
+
+ return (int) __socketcall( SYS_LISTEN, t );
+}
+#endif /* __NR_listen */
+
+#ifndef __NR_accept
+int accept(int sock, struct sockaddr *adresse, socklen_t *longueur)
+{
+ unsigned long t[3];
+
+ t[0] = (unsigned long) sock;
+ t[1] = (unsigned long) adresse;
+ t[2] = (unsigned long) longueur;
+
+ return (int) __socketcall( SYS_ACCEPT, t );
+}
+#endif /* __NR_accept */
+
+#ifndef __NR_getsockname
+int getsockname(int s, struct sockaddr * name, socklen_t * namelen )
+{
+ unsigned long t[3];
+
+ t[0] = (unsigned long) s;
+ t[1] = (unsigned long) name;
+ t[2] = (unsigned long) namelen;
+
+ return (int) __socketcall( SYS_GETSOCKNAME, t );
+}
+#endif /* __NR_getsockname */
+
+#ifndef __NR_getpeername
+int getpeername(int s, struct sockaddr *name, socklen_t *namelen)
+{
+ unsigned long t[3];
+
+ t[0] = (unsigned long) s;
+ t[1] = (unsigned long) name;
+ t[2] = (unsigned long) namelen;
+
+ return (int) __socketcall( SYS_GETPEERNAME, t );
+}
+#endif /* !__NR_getpeername */
+
+#ifndef __NR_socketpair
+int socketpair(int d, int type, int protocol, int sv[2])
+{
+ unsigned long t[4];
+
+ t[0] = (unsigned long) d;
+ t[1] = (unsigned long) type;
+ t[2] = (unsigned long) protocol;
+ t[3] = (unsigned long) sv;
+
+ return (int) __socketcall( SYS_SOCKETPAIR, t );
+}
+#endif /* __NR_socketpair */
+
+#ifndef __NR_sendto
+ssize_t sendto(int socket, const void *message, size_t length, int flags,
+ const struct sockaddr *dest_addr, socklen_t dest_len)
+{
+ unsigned long t[6];
+
+ t[0] = (unsigned long) socket;
+ t[1] = (unsigned long) message;
+ t[2] = (unsigned long) length;
+ t[3] = (unsigned long) flags;
+ t[4] = (unsigned long) dest_addr;
+ t[5] = (unsigned long) dest_len;
+
+ return __socketcall( SYS_SENDTO, t );
+}
+#endif /* !__NR_sendto */
+
+#ifndef __NR_recvfrom
+ssize_t recvfrom(int socket, void *buffer, size_t length, unsigned int flags,
+ const struct sockaddr *address, socklen_t *address_len)
+{
+ unsigned long t[6];
+
+ t[0] = (unsigned long) socket;
+ t[1] = (unsigned long) buffer;
+ t[2] = (unsigned long) length;
+ t[3] = (unsigned long) flags;
+ t[4] = (unsigned long) address;
+ t[5] = (unsigned long) address_len;
+
+ return __socketcall( SYS_RECVFROM, t );
+}
+#endif /* !__NR_recvfrom */
+
+#ifndef __NR_shutdown
+int shutdown(int socket, int how)
+{
+ unsigned long t[2];
+
+ t[0] = (unsigned long) socket;
+ t[1] = (unsigned long) how;
+
+ return (int) __socketcall( SYS_SHUTDOWN, t );
+}
+#endif /* !__NR_shutdown */
+
+#ifndef __NR_setsockopt
+int setsockopt( int s, int level, int optname, const void* optval, socklen_t optlen )
+{
+ unsigned long t[5];
+
+ t[0] = (unsigned long) s;
+ t[1] = (unsigned long) level;
+ t[2] = (unsigned long) optname;
+ t[3] = (unsigned long) optval;
+ t[4] = (unsigned long) optlen;
+
+ return (int) __socketcall( SYS_SETSOCKOPT, t );
+}
+#endif /* !__NR_setsockopt */
+
+#ifndef __NR_getsockopt
+int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
+{
+ unsigned long t[5];
+
+ t[0] = (unsigned long) s;
+ t[1] = (unsigned long) level;
+ t[2] = (unsigned long) optname;
+ t[3] = (unsigned long) optval;
+ t[4] = (unsigned long) optlen;
+
+ return (int) __socketcall( SYS_GETSOCKOPT, t );
+}
+#endif /* !__NR_getsockopt */
+
+#ifndef __NR_sendmsg
+int sendmsg (int socket, const struct msghdr *message, unsigned int flags)
+{
+ unsigned long t[3];
+
+ t[0] = (unsigned long) socket;
+ t[1] = (unsigned long) message;
+ t[2] = (unsigned long) flags;
+
+ return __socketcall( SYS_SENDMSG, t );
+}
+#endif /* __NR_sendmsg */
+
+#ifndef __NR_recvmsg
+int recvmsg(int socket, struct msghdr *message, unsigned int flags)
+{
+ unsigned long t[3];
+
+ t[0] = (unsigned long) socket;
+ t[1] = (unsigned long) message;
+ t[2] = (unsigned long) flags;
+
+ return __socketcall( SYS_RECVMSG, t );
+}
+#endif /* __NR_recvmsg */
+
diff --git a/libc/bionic/statfs.c b/libc/bionic/statfs.c
new file mode 100644
index 0000000..491ef7a
--- /dev/null
+++ b/libc/bionic/statfs.c
@@ -0,0 +1,35 @@
+/*
+ * 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 <sys/vfs.h>
+
+extern int __statfs64(const char *, size_t, struct statfs *);
+
+int statfs(const char* path, struct statfs* stat)
+{
+ return __statfs64(path, sizeof(struct statfs), stat);
+}
diff --git a/libc/bionic/strcoll.c b/libc/bionic/strcoll.c
new file mode 100755
index 0000000..e3b1ec3
--- /dev/null
+++ b/libc/bionic/strcoll.c
@@ -0,0 +1,40 @@
+/*
+ * 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/bionic/strndup.c b/libc/bionic/strndup.c
new file mode 100644
index 0000000..9dca79c
--- /dev/null
+++ b/libc/bionic/strndup.c
@@ -0,0 +1,44 @@
+/*
+ * 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/bionic/strnlen.c b/libc/bionic/strnlen.c
new file mode 100644
index 0000000..2c6f60a
--- /dev/null
+++ b/libc/bionic/strnlen.c
@@ -0,0 +1,38 @@
+/*
+ * 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/bionic/strntoimax.c b/libc/bionic/strntoimax.c
new file mode 100644
index 0000000..2f3cd9a
--- /dev/null
+++ b/libc/bionic/strntoimax.c
@@ -0,0 +1,34 @@
+/*
+ * 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 <inttypes.h>
+
+intmax_t strntoimax(const char *nptr, char **endptr, int base, size_t n)
+{
+ return (intmax_t) strntoumax(nptr, endptr, base, n);
+}
diff --git a/libc/bionic/strntoumax.c b/libc/bionic/strntoumax.c
new file mode 100644
index 0000000..050d718
--- /dev/null
+++ b/libc/bionic/strntoumax.c
@@ -0,0 +1,95 @@
+/*
+ * 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 <stdint.h>
+#include <ctype.h>
+
+static inline int digitval(int ch)
+{
+ unsigned d;
+
+ d = (unsigned)(ch - '0');
+ if (d < 10) return (int)d;
+
+ d = (unsigned)(ch - 'a');
+ if (d < 6) return (int)(d+10);
+
+ d = (unsigned)(ch - 'A');
+ if (d < 6) return (int)(d+10);
+
+ return -1;
+}
+
+uintmax_t
+strntoumax(const char *nptr, char **endptr, int base, size_t n)
+{
+ const unsigned char* p = (const unsigned char *)nptr;
+ const unsigned char* end = p + n;
+ int minus = 0;
+ uintmax_t v = 0;
+ int d;
+
+ /* skip leading space */
+ while (p < end && isspace(*p))
+ p++;
+
+ /* Single optional + or - */
+ if (p < end) {
+ char c = p[0];
+ if ( c == '-' || c == '+' ) {
+ minus = (c == '-');
+ p++;
+ }
+ }
+
+ if ( base == 0 ) {
+ if ( p+2 < end && p[0] == '0' && (p[1] == 'x' || p[1] == 'X') ) {
+ p += 2;
+ base = 16;
+ } else if ( p+1 < end && p[0] == '0' ) {
+ p += 1;
+ base = 8;
+ } else {
+ base = 10;
+ }
+ } else if ( base == 16 ) {
+ if ( p+2 < end && p[0] == '0' && (p[1] == 'x' || p[1] == 'X') ) {
+ p += 2;
+ }
+ }
+
+ while ( p < end && (d = digitval(*p)) >= 0 && d < base ) {
+ v = v*base + d;
+ p += 1;
+ }
+
+ if ( endptr )
+ *endptr = (char *)p;
+
+ return minus ? -v : v;
+}
diff --git a/libc/bionic/strtotimeval.c b/libc/bionic/strtotimeval.c
new file mode 100644
index 0000000..1c132ec
--- /dev/null
+++ b/libc/bionic/strtotimeval.c
@@ -0,0 +1,63 @@
+/*
+ * 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;
+}
diff --git a/libc/bionic/sysconf.c b/libc/bionic/sysconf.c
new file mode 100644
index 0000000..7caa4e9
--- /dev/null
+++ b/libc/bionic/sysconf.c
@@ -0,0 +1,341 @@
+/*
+ * 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 <asm/page.h>
+#include <bionic_tls.h>
+#include <ctype.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <stdio.h> // For FOPEN_MAX.
+#include <string.h>
+#include <sys/sysconf.h>
+#include <unistd.h>
+
+/* seems to be the default on Linux, per the GLibc sources and my own digging */
+
+#define SYSTEM_CLK_TCK 100
+#define SYSTEM_IOV_MAX 1024
+#define SYSTEM_DELAYTIMER_MAX 2147483647
+#define SYSTEM_MQ_OPEN_MAX 8
+#define SYSTEM_MQ_PRIO_MAX 32768
+#define SYSTEM_SEM_NSEMS_MAX 256
+#define SYSTEM_SEM_VALUE_MAX 0x3fffffff /* see bionic/semaphore.c */
+#define SYSTEM_SIGQUEUE_MAX 32
+#define SYSTEM_TIMER_MAX 32
+#define SYSTEM_LOGIN_NAME_MAX 256
+#define SYSTEM_TTY_NAME_MAX 32
+
+/* the following depends on our implementation */
+#define SYSTEM_ATEXIT_MAX 65536 /* our implementation is unlimited */
+#define SYSTEM_THREAD_KEYS_MAX BIONIC_TLS_SLOTS
+#define SYSTEM_THREAD_STACK_MIN 32768 /* lower values may be possible, but be conservative */
+#define SYSTEM_THREAD_THREADS_MAX 2048 /* really unlimited */
+
+#define SYSTEM_2_C_BIND _POSIX_VERSION /* Posix C binding version */
+#define SYSTEM_2_C_VER _POSIX2_C_VERSION
+#define SYSTEM_2_C_DEV -1 /* Posix C development tools unsupported on the device */
+#define SYSTEM_2_FORT_DEV -1 /* Fortran development unsupported */
+#define SYSTEM_2_FORT_RUN -1 /* Fortran runtime unsupported */
+#define SYSTEM_2_SW_DEV -1 /* posix software dev utilities unsupported */
+#define SYSTEM_2_LOCALEDEF -1 /* localedef() unimplemented */
+#define SYSTEM_2_UPE -1 /* No UPE for you ! (User Portability Utilities) */
+#define SYSTEM_2_VERSION -1 /* No posix command-line tools */
+
+static bool __matches_cpuN(const char* s) {
+ // The %c trick is to ensure that we have the anchored match "^cpu[0-9]+$".
+ unsigned cpu;
+ char dummy;
+ return (sscanf(s, "cpu%u%c", &cpu, &dummy) == 1);
+}
+
+static int __get_nproc_conf(void) {
+ // On x86 kernels you can use /proc/cpuinfo for this, but on ARM kernels offline CPUs disappear
+ // from there. This method works on both.
+ DIR* d = opendir("/sys/devices/system/cpu");
+ if (!d) {
+ return 1;
+ }
+
+ int result = 0;
+ struct dirent de;
+ struct dirent* e;
+ while (!readdir_r(d, &de, &e) && e != NULL) {
+ if (e->d_type == DT_DIR && __matches_cpuN(e->d_name)) {
+ ++result;
+ }
+ }
+ closedir(d);
+ return result;
+}
+
+static int __get_nproc_onln(void) {
+ FILE* fp = fopen("/proc/stat", "r");
+ if (fp == NULL) {
+ return 1;
+ }
+
+ int result = 0;
+ char buf[256];
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ // Extract just the first word from the line.
+ // 'cpu0 7976751 1364388 3116842 469770388 8629405 0 49047 0 0 0'
+ char* p = strchr(buf, ' ');
+ if (p != NULL) {
+ *p = 0;
+ }
+ if (__matches_cpuN(buf)) {
+ ++result;
+ }
+ }
+ fclose(fp);
+ return result;
+}
+
+static int __get_meminfo(const char* pattern) {
+ FILE* fp = fopen("/proc/meminfo", "r");
+ if (fp == NULL) {
+ return -1;
+ }
+
+ int result = -1;
+ char buf[256];
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ long total;
+ if (sscanf(buf, pattern, &total) == 1) {
+ result = (int) (total / (PAGE_SIZE/1024));
+ break;
+ }
+ }
+ fclose(fp);
+ return result;
+}
+
+static int __get_phys_pages(void) {
+ return __get_meminfo("MemTotal: %ld kB");
+}
+
+static int __get_avphys_pages(void) {
+ return __get_meminfo("MemFree: %ld kB");
+}
+
+int sysconf(int name) {
+ switch (name) {
+#ifdef _POSIX_ARG_MAX
+ case _SC_ARG_MAX: return _POSIX_ARG_MAX;
+#endif
+#ifdef _POSIX2_BC_BASE_MAX
+ case _SC_BC_BASE_MAX: return _POSIX2_BC_BASE_MAX;
+#endif
+#ifdef _POSIX2_BC_DIM_MAX
+ case _SC_BC_DIM_MAX: return _POSIX2_BC_DIM_MAX;
+#endif
+#ifdef _POSIX2_BC_SCALE_MAX
+ case _SC_BC_SCALE_MAX: return _POSIX2_BC_SCALE_MAX;
+#endif
+#ifdef _POSIX2_BC_STRING_MAX
+ case _SC_BC_STRING_MAX: return _POSIX2_BC_STRING_MAX;
+#endif
+ case _SC_CHILD_MAX: return CHILD_MAX;
+ case _SC_CLK_TCK: return SYSTEM_CLK_TCK;
+#ifdef _POSIX2_COLL_WEIGHTS_MASK
+ case _SC_COLL_WEIGHTS_MAX: return _POSIX2_COLL_WEIGHTS_MASK;
+#endif
+#ifdef _POSIX2_EXPR_NEST_MAX
+ case _SC_EXPR_NEST_MAX: return _POSIX2_EXPR_NEST_MAX;
+#endif
+#ifdef _POSIX2_LINE_MAX
+ case _SC_LINE_MAX: return _POSIX2_LINE_MAX;
+#endif
+ case _SC_NGROUPS_MAX: return NGROUPS_MAX;
+ case _SC_OPEN_MAX: return OPEN_MAX;
+ //case _SC_PASS_MAX: return PASS_MAX;
+ case _SC_2_C_BIND: return SYSTEM_2_C_BIND;
+ case _SC_2_C_DEV: return SYSTEM_2_C_DEV;
+ case _SC_2_C_VERSION: return SYSTEM_2_C_VER;
+ //case _SC_2_CHAR_TERM: return ;
+ case _SC_2_FORT_DEV: return SYSTEM_2_FORT_DEV;
+ case _SC_2_FORT_RUN: return SYSTEM_2_FORT_RUN;
+ case _SC_2_LOCALEDEF: return SYSTEM_2_LOCALEDEF;
+ case _SC_2_SW_DEV: return SYSTEM_2_SW_DEV;
+ case _SC_2_UPE: return SYSTEM_2_UPE;
+ case _SC_2_VERSION: return SYSTEM_2_VERSION;
+#ifdef _POSIX_JOB_CONTROL
+ case _SC_JOB_CONTROL: return _POSIX_JOB_CONTROL;
+#endif
+#ifdef _POSIX_SAVED_IDS
+ case _SC_SAVED_IDS: return _POSIX_SAVED_IDS;
+#endif
+#ifdef _POSIX_VERSION
+ case _SC_VERSION: return _POSIX_VERSION;
+#endif
+ //case _SC_RE_DUP_<AX: return ;
+ case _SC_STREAM_MAX: return FOPEN_MAX;
+ //case _SC_TZNAME_MAX: return ;
+#if _XOPEN_CRYPT
+ case _SC_XOPEN_CRYPT: return _XOPEN_CRYPT;
+#endif
+#ifdef _XOPEN_ENH_I18N
+ case _SC_XOPEN_ENH_I18N: return _XOPEN_ENH_I18N;
+#endif
+#ifdef _XOPEN_SHM
+ case _SC_XOPEN_SHM: return _XOPEN_SHM;
+#endif
+#ifdef _XOPEN_VERSION
+ case _SC_XOPEN_VERSION: return _XOPEN_VERSION;
+#endif
+#ifdef _XOPEN_XCU_VERSION
+ case _SC_XOPEN_XCU_VERSION: return _XOPEN_XCU_VERSION;
+#endif
+#ifdef _XOPEN_REALTIME
+ case _SC_XOPEN_REALTIME: return _XOPEN_REALTIME;
+#endif
+#ifdef _XOPEN_REALTIME_THREADS
+ case _SC_XOPEN_REALTIME_THREADS: return _XOPEN_REALTIME_THREADS;
+#endif
+#ifdef _XOPEN_LEGACY
+ case _SC_XOPEN_LEGACY: return _XOPEN_LEGACY;
+#endif
+ case _SC_ATEXIT_MAX: return SYSTEM_ATEXIT_MAX;
+ case _SC_IOV_MAX: return SYSTEM_IOV_MAX;
+ case _SC_PAGESIZE: return PAGE_SIZE;
+ case _SC_PAGE_SIZE: return PAGE_SIZE;
+#ifdef _XOPEN_UNIX
+ case _SC_XOPEN_UNIX: return _XOPEN_UNIX;
+#endif
+
+ // XXX: TODO: XBS5 nonsense
+
+#ifdef AIO_LISTIO_MAX
+ case _SC_AIO_LISTIO_MAX: return AIO_LISTIO_MAX;
+#endif
+#ifdef AIO_MAX
+ case _SC_AIO_MAX: return AIO_MAX;
+#endif
+#ifdef AIO_PRIO_DELTA_MAX
+ case _SC_AIO_PRIO_DELTA_MAX: return AIO_PRIO_DELTA_MAX;
+#endif
+ case _SC_DELAYTIMER_MAX: return SYSTEM_DELAYTIMER_MAX;
+ case _SC_MQ_OPEN_MAX: return SYSTEM_MQ_OPEN_MAX;
+ case _SC_MQ_PRIO_MAX: return SYSTEM_MQ_PRIO_MAX;
+ case _SC_RTSIG_MAX: return RTSIG_MAX;
+ case _SC_SEM_NSEMS_MAX: return SYSTEM_SEM_NSEMS_MAX;
+ case _SC_SEM_VALUE_MAX: return SYSTEM_SEM_VALUE_MAX;
+ case _SC_SIGQUEUE_MAX: return SYSTEM_SIGQUEUE_MAX;
+ case _SC_TIMER_MAX: return SYSTEM_TIMER_MAX;
+#ifdef _POSIX_ASYNCHRONOUS_IO
+ case _SC_ASYNCHRONOUS_IO: return _POSIX_ASYNCHRONOUS_IO;
+#endif
+#ifdef _POSIX_FSYNC
+ case _SC_FSYNC: return _POSIX_FSYNC;
+#endif
+#ifdef _POSIX_MAPPED_FILES
+ case _SC_MAPPED_FILES: return _POSIX_MAPPED_FILES;
+#endif
+#ifdef _POSIX_MEMLOCK
+ case _SC_MEMLOCK: return _POSIX_MEMLOCK;
+#endif
+#ifdef _POSIX_MEMLOCK_RANGE
+ case _SC_MEMLOCK_RANGE: return _POSIX_MEMLOCK_RANGE
+#endif
+#ifdef _POSIX_MEMORY_PROTECTION
+ case _SC_MEMORY_PROTECTION: return _POSIX_MEMORY_PROTECTION;
+#endif
+#ifdef _POSIX_MESSAGE_PASSING
+ case _SC_MESSAGE_PASSING: return _POSIX_MESSAGE_PASSING;
+#endif
+#ifdef _POSIX_PRIORITIZED_IO
+ case _SC_PRIORITIZED_IO: return _POSIX_PRIORITIZED_IO;
+#endif
+#ifdef _POSIX_PRIORITY_SCHEDULING
+ case _SC_PRIORITY_SCHEDULING: return _POSIX_PRIORITY_SCHEDULING;
+#endif
+#ifdef _POSIX_REALTIME_SIGNALS
+ case _SC_REALTIME_SIGNALS: return _POSIX_REALTIME_SIGNALS;
+#endif
+#ifdef _POSIX_SEMAPHORES
+ case _SC_SEMAPHORES: return _POSIX_SEMAPHORES;
+#endif
+#ifdef _POSIX_SHARED_MEMORY_OBJECTS
+ case _SC_SHARED_MEMORY_OBJECTS: return _POSIX_SHARED_MEMORY_OBJECTS;
+#endif
+#ifdef _POSIX_SYNCHRONIZED_IO
+ case _SC_SYNCHRONIZED_IO: return _POSIX_SYNCHRONIZED_IO;
+#endif
+#ifdef _POSIX_TIMERS
+ case _SC_TIMERS: return _POSIX_TIMERS;
+#endif
+
+ // GETGR_R_SIZE_MAX ?
+ // GETPW_R_SIZE_MAX ?
+
+ case _SC_LOGIN_NAME_MAX: return SYSTEM_LOGIN_NAME_MAX;
+#ifdef _POSIX_THREAD_DESTRUCTOR_ITERATIONS
+ case _SC_THREAD_DESTRUCTOR_ITERATIONS: return _POSIX_THREAD_DESTRUCTOR_ITERATIONS;
+#endif
+ case _SC_THREAD_KEYS_MAX: return SYSTEM_THREAD_KEYS_MAX;
+ case _SC_THREAD_STACK_MIN: return SYSTEM_THREAD_STACK_MIN;
+ case _SC_THREAD_THREADS_MAX: return SYSTEM_THREAD_THREADS_MAX;
+ case _SC_TTY_NAME_MAX: return SYSTEM_TTY_NAME_MAX;
+#ifdef _POSIX_THREADS
+ case _SC_THREADS: return _POSIX_THREADS;
+#endif
+#ifdef _POSIX_THREAD_ATTR_STACKADDR
+ case _SC_THREAD_ATTR_STACKADDR: return _POSIX_THREAD_ATTR_STACKADDR;
+#endif
+#ifdef _POSIX_THREAD_ATTR_STACKSIZE
+ case _SC_THREAD_ATTR_STACKSIZE: return _POSIX_THREAD_ATTR_STACKSIZE;
+#endif
+#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
+ case _SC_THREAD_PRIORITY_SCHEDULING: return _POSIX_THREAD_PRIORITY_SCHEDULING;
+#endif
+#ifdef _POSIX_THREAD_PRIO_INHERIT
+ case _SC_THREAD_PRIO_INHERIT: return _POSIX_THREAD_PRIO_INHERIT;
+#endif
+#ifdef _POSIX_THREAD_PRIO_PROTECT
+ case _SC_THREAD_PRIO_PROTECT: return _POSIX_THREAD_PRIO_PROTECT;
+#endif
+#ifdef _POSIX_THREAD_SAFE_FUNCTIONS
+ case _SC_THREAD_SAFE_FUNCTIONS: return _POSIX_THREAD_SAFE_FUNCTIONS
+#endif
+
+
+ case _SC_NPROCESSORS_CONF: return __get_nproc_conf();
+ case _SC_NPROCESSORS_ONLN: return __get_nproc_onln();
+ case _SC_PHYS_PAGES: return __get_phys_pages();
+ case _SC_AVPHYS_PAGES: return __get_avphys_pages();
+
+ default:
+ /* Posix says EINVAL is the only error that shall be returned,
+ * but GLibc uses ENOSYS */
+ errno = ENOSYS;
+ return -1;
+ }
+}
diff --git a/libc/bionic/tcgetpgrp.c b/libc/bionic/tcgetpgrp.c
new file mode 100644
index 0000000..4355014
--- /dev/null
+++ b/libc/bionic/tcgetpgrp.c
@@ -0,0 +1,34 @@
+/* bionic/unistd/tcgetpgrp.c
+**
+** Copyright 2006, The Android Open Source Project
+**
+** 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.
+** * Neither the name of Google Inc. 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 Google Inc. ``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 Google Inc. 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 <unistd.h>
+#include <termios.h>
+
+pid_t tcgetpgrp(int fd)
+{
+ pid_t _pid;
+ return ioctl(fd, TIOCGPGRP, &_pid) ? (pid_t)-1 : _pid;
+}
diff --git a/libc/bionic/tcsetpgrp.c b/libc/bionic/tcsetpgrp.c
new file mode 100644
index 0000000..b83b997
--- /dev/null
+++ b/libc/bionic/tcsetpgrp.c
@@ -0,0 +1,33 @@
+/* bionic/unistd/tcsetpgrp.c
+**
+** Copyright 2006, The Android Open Source Project
+**
+** 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.
+** * Neither the name of Google Inc. 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 Google Inc. ``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 Google Inc. 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 <unistd.h>
+#include <termios.h>
+
+int tcsetpgrp(int fd, pid_t _pid)
+{
+ return ioctl(fd, TIOCSPGRP, &_pid);
+}
diff --git a/libc/bionic/umount.c b/libc/bionic/umount.c
new file mode 100644
index 0000000..642e42c
--- /dev/null
+++ b/libc/bionic/umount.c
@@ -0,0 +1,35 @@
+/*
+ * 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 <unistd.h>
+
+extern int umount2(const char*, int);
+
+int umount(const char* dir)
+{
+ return umount2(dir, 0);
+}
diff --git a/libc/bionic/unlockpt.c b/libc/bionic/unlockpt.c
new file mode 100644
index 0000000..998b7a3
--- /dev/null
+++ b/libc/bionic/unlockpt.c
@@ -0,0 +1,36 @@
+/*
+ * 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 <unistd.h>
+#include <sys/ioctl.h>
+
+int unlockpt( int fd )
+{
+ int unlock = 0;
+
+ return ioctl( fd, TIOCSPTLCK, &unlock );
+}
diff --git a/libc/bionic/usleep.c b/libc/bionic/usleep.c
new file mode 100644
index 0000000..19e8ee8
--- /dev/null
+++ b/libc/bionic/usleep.c
@@ -0,0 +1,55 @@
+/*
+ * 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 <time.h>
+#include <errno.h>
+
+int usleep(unsigned long usec)
+{
+ struct timespec ts;
+
+ ts.tv_sec = usec/1000000UL;
+
+#ifdef __arm__
+ /* avoid divisions and modulos on the ARM */
+ ts.tv_nsec = (usec - ts.tv_sec*1000000UL)*1000;
+#else
+ ts.tv_nsec = (usec % 1000000UL) * 1000UL;
+#endif
+
+ for (;;)
+ {
+ if ( nanosleep( &ts, &ts ) == 0 )
+ return 0;
+
+ // We try again if the nanosleep failure is EINTR.
+ // The other possible failures are EINVAL (which we should pass through),
+ // and ENOSYS, which doesn't happen.
+ if ( errno != EINTR )
+ return -1;
+ }
+}
diff --git a/libc/bionic/wait.c b/libc/bionic/wait.c
new file mode 100644
index 0000000..f1db086
--- /dev/null
+++ b/libc/bionic/wait.c
@@ -0,0 +1,53 @@
+/*
+ * 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 <sys/wait.h>
+#include <stddef.h>
+
+extern pid_t __wait4 (pid_t pid, int *status, int options, struct rusage *rusage);
+extern int __waitid(idtype_t which, id_t id, siginfo_t *info, int options, struct rusage *ru);
+
+pid_t wait( int* status )
+{
+ return __wait4( (pid_t)-1, status, 0, NULL );
+}
+
+pid_t wait3(int* status, int options, struct rusage* rusage)
+{
+ return __wait4( (pid_t)-1, status, options, rusage );
+}
+
+pid_t waitpid(pid_t pid, int* status, int options)
+{
+ return __wait4( pid, status, options, NULL );
+}
+
+int waitid(idtype_t which, id_t id, siginfo_t *info, int options)
+{
+ /* the system call takes an option struct rusage that we don't need */
+ return __waitid(which, id, info, options, NULL);
+}
diff --git a/libc/bionic/wchar.c b/libc/bionic/wchar.c
new file mode 100644
index 0000000..d83613a
--- /dev/null
+++ b/libc/bionic/wchar.c
@@ -0,0 +1,330 @@
+/*
+ * 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 <wchar.h>
+#include <ctype.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+/* stubs for wide-char functions */
+wint_t btowc(int c)
+{
+ return (c == EOF) ? WEOF : c;
+}
+
+int fwprintf(FILE *stream, const wchar_t *format, ...)
+{
+ va_list args;
+ int result;
+
+ va_start(args, format);
+ result = vfwprintf(stream, format, args);
+ va_end(args);
+ return result;
+}
+
+int wprintf(const wchar_t *format, ...)
+{
+ va_list args;
+ int result;
+
+ va_start(args, format);
+ result = vwprintf(format, args);
+ va_end(args);
+ return result;
+}
+
+int swprintf(wchar_t *s, size_t n, const wchar_t *format, ...)
+{
+ va_list args;
+ int result;
+
+ va_start(args, format);
+ result = vswprintf(s, n, format, args);
+ va_end(args);
+ return result;
+}
+
+int vwprintf(const wchar_t *format, va_list arg)
+{
+ return vfwprintf(stdout, format, arg);
+}
+
+int vfwprintf(FILE *stream, const wchar_t *format, va_list arg)
+{
+ errno = ENOTSUP;
+ return -1;
+}
+
+int vswprintf(wchar_t *s, size_t n, const wchar_t *format, va_list arg)
+{
+ errno = ENOTSUP;
+ return -1;
+}
+
+int fwscanf(FILE *stream, const wchar_t *format, ... )
+{
+ errno = ENOTSUP;
+ return -1;
+}
+
+int wscanf(const wchar_t *format, ... )
+{
+ va_list args;
+ int result;
+
+ va_start (args, format);
+ result = fwscanf(stdout, format, args );
+ va_end (args);
+ return result;
+}
+
+int swscanf(const wchar_t *s, const wchar_t *format, ... )
+{
+ errno = ENOTSUP;
+ return -1;
+}
+
+int iswalnum(wint_t wc) { return isalnum(wc); }
+int iswalpha(wint_t wc) { return isalpha(wc); }
+int iswcntrl(wint_t wc) { return iscntrl(wc); }
+int iswdigit(wint_t wc) { return isdigit(wc); }
+int iswgraph(wint_t wc) { return isgraph(wc); }
+int iswlower(wint_t wc) { return islower(wc); }
+int iswprint(wint_t wc) { return isprint(wc); }
+int iswpunct(wint_t wc) { return ispunct(wc); }
+int iswspace(wint_t wc) { return isspace(wc); }
+int iswupper(wint_t wc) { return isupper(wc); }
+int iswxdigit(wint_t wc) { return isxdigit(wc); }
+
+int iswctype(wint_t wc, wctype_t charclass)
+{
+ switch (charclass) {
+ case WC_TYPE_ALNUM: return isalnum(wc);
+ case WC_TYPE_ALPHA: return isalpha(wc);
+ case WC_TYPE_BLANK: return isblank(wc);
+ case WC_TYPE_CNTRL: return iscntrl(wc);
+ case WC_TYPE_DIGIT: return isdigit(wc);
+ case WC_TYPE_GRAPH: return isgraph(wc);
+ case WC_TYPE_LOWER: return islower(wc);
+ case WC_TYPE_PRINT: return isprint(wc);
+ case WC_TYPE_PUNCT: return ispunct(wc);
+ case WC_TYPE_SPACE: return isspace(wc);
+ case WC_TYPE_UPPER: return isupper(wc);
+ case WC_TYPE_XDIGIT: return isxdigit(wc);
+ default: return 0;
+ };
+}
+
+wint_t fgetwc(FILE *stream)
+{
+ return (wint_t)fgetc(stream);
+}
+
+wchar_t *fgetws(wchar_t *ws, int n, FILE *stream)
+{
+ return (wchar_t*) fgets((char*)ws, n, stream);
+}
+
+wint_t fputwc(wchar_t wc, FILE *stream)
+{
+ return (wint_t)fputc((char)wc, stream);
+}
+
+int fputws(const wchar_t *str, FILE *stream)
+{
+ return fputs( (const char*)str, stream );
+}
+
+int fwide(FILE *stream, int mode)
+{
+ stream=stream;
+ return (mode);
+}
+
+wint_t getwc(FILE *stream)
+{
+ return getc(stream);
+}
+
+wint_t getwchar(void)
+{
+ return getchar();
+}
+
+int mbsinit(const mbstate_t *ps)
+{
+ ps=ps;
+ return 1;
+}
+
+size_t mbrlen(const char *s, size_t n, mbstate_t *ps)
+{
+ return (n != 0);
+}
+
+size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
+{
+ if (s == NULL) {
+ s = "";
+ pwc = NULL;
+ }
+ if (n == 0) {
+ if (pwc)
+ *pwc = 0;
+ return 0;
+ }
+ if (pwc)
+ *pwc = *s;
+
+ return (*s != 0);
+}
+
+size_t mbsrtowcs(wchar_t *dst, const char **src, size_t len, mbstate_t *ps)
+{
+ const char* s = *src;
+ const char* s2 = memchr( s, 0, len );
+
+ if (s2 != NULL)
+ len = (size_t)(s2 - s) + 1U;
+
+ if (dst)
+ memcpy( (char*)dst, s, len );
+
+ *src = s + len;
+ return len;
+}
+
+size_t mbstowcs(wchar_t *dst, const char *src, size_t len)
+{
+ return mbsrtowcs(dst, &src, len, NULL);
+}
+
+wint_t putwc(wchar_t wc, FILE *stream)
+{
+ return fputc((char)wc, stream);
+}
+
+wint_t putwchar(wchar_t wc)
+{
+ return putchar((char)wc);
+}
+
+wint_t towlower(wint_t wc)
+{
+ return tolower(wc);
+}
+
+wint_t towupper(wint_t wc)
+{
+ return toupper(wc);
+}
+
+wint_t ungetwc(wint_t wc, FILE *stream)
+{
+ return ungetc((char)wc, stream);
+}
+
+size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps)
+{
+ if (s != NULL)
+ *s = 1;
+ return 1;
+}
+
+size_t wcsftime(wchar_t *wcs, size_t maxsize, const wchar_t *format, const struct tm *timptr)
+{
+ return strftime( (char*)wcs, maxsize, (const char*)format, timptr );
+}
+
+size_t wcsrtombs(char *dst, const wchar_t **src, size_t len, mbstate_t *ps)
+{
+ const char* s = (const char*)*src;
+ const char* s2 = memchr( s, 0, len );
+
+ if (s2 != NULL)
+ len = (s2 - s)+1;
+
+ if (dst != NULL)
+ memcpy( dst, s, len );
+
+ *src = (wchar_t*)(s + len);
+ return len;
+}
+
+size_t wcstombs(char *dst, const wchar_t *src, size_t len)
+{
+ return wcsrtombs(dst, &src, len, NULL);
+}
+
+double wcstod(const wchar_t *nptr, wchar_t **endptr)
+{
+ return strtod( (const char*)nptr, (char**)endptr );
+}
+
+long int wcstol(const wchar_t *nptr, wchar_t **endptr, int base)
+{
+ return strtol( (const char*)nptr, (char**)endptr, base );
+}
+
+unsigned long int wcstoul(const wchar_t *nptr, wchar_t **endptr, int base)
+{
+ return strtoul( (const char*)nptr, (char**)endptr, base );
+}
+
+wchar_t *wcswcs(const wchar_t *ws1, const wchar_t *ws2)
+{
+ return (wchar_t*) strstr( (const char*)ws1, (const char*)ws2 );
+}
+
+int wctob(wint_t c)
+{
+ return c;
+}
+
+wctype_t wctype(const char *property)
+{
+ static const char* const properties[WC_TYPE_MAX] =
+ {
+ "<invalid>",
+ "alnum", "alpha", "blank", "cntrl", "digit", "graph",
+ "lower", "print", "punct", "space", "upper", "xdigit"
+ };
+ int nn;
+
+ for ( nn = 0; nn < WC_TYPE_MAX; nn++ )
+ if ( !strcmp( properties[nn], property ) )
+ return (wctype_t)(nn);
+
+ return 0;
+}
+
+int wcwidth(wchar_t wc)
+{
+ return (wc > 0);
+}
diff --git a/libc/bionic/wcscoll.c b/libc/bionic/wcscoll.c
new file mode 100644
index 0000000..6e843b7
--- /dev/null
+++ b/libc/bionic/wcscoll.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2010 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>
+/*
+ * Compare strings using the current locale. Since Bionic really does not
+ * support locales, we assume we always use the C locale and call wcscmp.
+ *
+ * This function is provided to make libstdc++-v3 usable.
+ */
+int
+wcscoll(const wchar_t *ws1, const wchar_t *ws2)
+{
+ return wcscmp(ws1, ws2);
+}