Merge "Changed long double literal suffix from 'l' to 'L'."
diff --git a/libc/Android.mk b/libc/Android.mk
index 3faa47f..44bf388 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -292,6 +292,7 @@
upstream-netbsd/lib/libc/stdlib/ldiv.c \
upstream-netbsd/lib/libc/stdlib/lldiv.c \
upstream-netbsd/lib/libc/stdlib/lrand48.c \
+ upstream-netbsd/lib/libc/stdlib/lsearch.c \
upstream-netbsd/lib/libc/stdlib/mrand48.c \
upstream-netbsd/lib/libc/stdlib/nrand48.c \
upstream-netbsd/lib/libc/stdlib/_rand48.c \
diff --git a/libc/arch-arm/include/machine/limits.h b/libc/arch-arm/include/machine/limits.h
deleted file mode 100644
index f9c04fa..0000000
--- a/libc/arch-arm/include/machine/limits.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* $OpenBSD: limits.h,v 1.3 2006/01/06 22:48:46 millert Exp $ */
-/* $NetBSD: limits.h,v 1.4 2003/04/28 23:16:18 bjh21 Exp $ */
-
-/*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University 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 THE REGENTS 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 REGENTS 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.
- *
- * from: @(#)limits.h 7.2 (Berkeley) 6/28/90
- */
-
-#ifndef _ARM32_LIMITS_H_
-#define _ARM32_LIMITS_H_
-
-#include <sys/cdefs.h>
-
-#define MB_LEN_MAX 1 /* no multibyte characters */
-
-#ifndef SIZE_MAX
-#define SIZE_MAX UINT_MAX /* max value for a size_t */
-#endif
-#ifndef SSIZE_MAX
-#define SSIZE_MAX INT_MAX /* max value for a ssize_t */
-#endif
-
-#if __BSD_VISIBLE
-#define SIZE_T_MAX UINT_MAX /* max value for a size_t (historic) */
-
-#define UQUAD_MAX 0xffffffffffffffffULL /* max unsigned quad */
-#define QUAD_MAX 0x7fffffffffffffffLL /* max signed quad */
-#define QUAD_MIN (-0x7fffffffffffffffLL-1) /* min signed quad */
-
-#endif /* __BSD_VISIBLE */
-
-#define LONGLONG_BIT 64
-#define LONGLONG_MIN (-9223372036854775807LL-1)
-#define LONGLONG_MAX 9223372036854775807LL
-#define ULONGLONG_MAX 18446744073709551615ULL
-
-#endif /* _ARM32_LIMITS_H_ */
diff --git a/libc/arch-arm64/include/machine/limits.h b/libc/arch-arm64/include/machine/limits.h
deleted file mode 100644
index ecddb01..0000000
--- a/libc/arch-arm64/include/machine/limits.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/* $OpenBSD: limits.h,v 1.3 2006/01/06 22:48:46 millert Exp $ */
-/* $NetBSD: limits.h,v 1.4 2003/04/28 23:16:18 bjh21 Exp $ */
-
-/*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University 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 THE REGENTS 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 REGENTS 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.
- *
- * from: @(#)limits.h 7.2 (Berkeley) 6/28/90
- */
-
-#ifndef _AARCH64_LIMITS_H_
-#define _AARCH64_LIMITS_H_
-
-#include <sys/cdefs.h>
-
-#define MB_LEN_MAX 1 /* no multibyte characters */
-
-#define LONGLONG_BIT 64
-#define LONGLONG_MIN (-9223372036854775807LL-1)
-#define LONGLONG_MAX 9223372036854775807LL
-#define ULONGLONG_MAX 18446744073709551615ULL
-
-#ifndef SIZE_MAX
-#define SIZE_MAX ULONGLONG_MAX /* max value for a size_t */
-#endif
-#ifndef SSIZE_MAX
-#define SSIZE_MAX LONGLONG_MAX /* max value for a ssize_t */
-#endif
-
-#if __BSD_VISIBLE
-#define SIZE_T_MAX ULONG_MAX /* max value for a size_t (historic) */
-
-#define UQUAD_MAX 0xffffffffffffffffULL /* max unsigned quad */
-#define QUAD_MAX 0x7fffffffffffffffLL /* max signed quad */
-#define QUAD_MIN (-0x7fffffffffffffffLL-1) /* min signed quad */
-
-#endif /* __BSD_VISIBLE */
-#endif /* _AARCH64_LIMITS_H_ */
diff --git a/libc/arch-mips/include/machine/limits.h b/libc/arch-mips/include/machine/limits.h
deleted file mode 100644
index 339444d..0000000
--- a/libc/arch-mips/include/machine/limits.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/* $OpenBSD: limits.h,v 1.5 2007/05/07 20:51:07 kettenis Exp $ */
-
-/*
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University 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 THE REGENTS 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 REGENTS 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.
- *
- * @(#)limits.h 8.3 (Berkeley) 1/4/94
- */
-
-#ifndef _MIPS_LIMITS_H_
-#define _MIPS_LIMITS_H_
-
-#include <sys/cdefs.h>
-
-#define MB_LEN_MAX 6 /* Allow 31 bit UTF2 */
-
-#ifndef SIZE_MAX
-#define SIZE_MAX ULONG_MAX /* max value for a size_t */
-#endif
-#define SSIZE_MAX LONG_MAX /* max value for a ssize_t */
-
-#if __BSD_VISIBLE
-#define SIZE_T_MAX ULONG_MAX /* max value for a size_t (historic) */
-
-/* Quads and longs are the same on mips64 */
-#define UQUAD_MAX (ULONG_MAX) /* max value for a uquad_t */
-#define QUAD_MAX (LONG_MAX) /* max value for a quad_t */
-#define QUAD_MIN (LONG_MIN) /* min value for a quad_t */
-
-#endif /* __BSD_VISIBLE */
-
-
-#define LONGLONG_BIT 64
-#define LONGLONG_MIN (-9223372036854775807LL-1)
-#define LONGLONG_MAX 9223372036854775807LL
-#define ULONGLONG_MAX 18446744073709551615ULL
-
-#endif /* !_MIPS_LIMITS_H_ */
diff --git a/libc/arch-mips64/include/machine/limits.h b/libc/arch-mips64/include/machine/limits.h
deleted file mode 100644
index 339444d..0000000
--- a/libc/arch-mips64/include/machine/limits.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/* $OpenBSD: limits.h,v 1.5 2007/05/07 20:51:07 kettenis Exp $ */
-
-/*
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University 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 THE REGENTS 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 REGENTS 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.
- *
- * @(#)limits.h 8.3 (Berkeley) 1/4/94
- */
-
-#ifndef _MIPS_LIMITS_H_
-#define _MIPS_LIMITS_H_
-
-#include <sys/cdefs.h>
-
-#define MB_LEN_MAX 6 /* Allow 31 bit UTF2 */
-
-#ifndef SIZE_MAX
-#define SIZE_MAX ULONG_MAX /* max value for a size_t */
-#endif
-#define SSIZE_MAX LONG_MAX /* max value for a ssize_t */
-
-#if __BSD_VISIBLE
-#define SIZE_T_MAX ULONG_MAX /* max value for a size_t (historic) */
-
-/* Quads and longs are the same on mips64 */
-#define UQUAD_MAX (ULONG_MAX) /* max value for a uquad_t */
-#define QUAD_MAX (LONG_MAX) /* max value for a quad_t */
-#define QUAD_MIN (LONG_MIN) /* min value for a quad_t */
-
-#endif /* __BSD_VISIBLE */
-
-
-#define LONGLONG_BIT 64
-#define LONGLONG_MIN (-9223372036854775807LL-1)
-#define LONGLONG_MAX 9223372036854775807LL
-#define ULONGLONG_MAX 18446744073709551615ULL
-
-#endif /* !_MIPS_LIMITS_H_ */
diff --git a/libc/arch-x86/include/machine/limits.h b/libc/arch-x86/include/machine/limits.h
deleted file mode 100644
index 86fd854..0000000
--- a/libc/arch-x86/include/machine/limits.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* $OpenBSD: limits.h,v 1.11 2006/01/06 22:48:47 millert Exp $ */
-/* $NetBSD: limits.h,v 1.11 1995/12/21 01:08:59 mycroft Exp $ */
-
-/*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University 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 THE REGENTS 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 REGENTS 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.
- *
- * @(#)limits.h 7.2 (Berkeley) 6/28/90
- */
-
-#ifndef _MACHINE_LIMITS_H_
-#define _MACHINE_LIMITS_H_
-
-#include <sys/cdefs.h>
-
-#define MB_LEN_MAX 1 /* no multibyte characters */
-
-#ifndef SIZE_MAX
-#define SIZE_MAX UINT_MAX /* max value for a size_t */
-#endif
-#ifndef SSIZE_MAX
-#define SSIZE_MAX INT_MAX /* max value for a ssize_t */
-#endif
-
-#if __BSD_VISIBLE
-#define SIZE_T_MAX UINT_MAX /* max value for a size_t (historic) */
-
-#define UQUAD_MAX 0xffffffffffffffffULL /* max unsigned quad */
-#define QUAD_MAX 0x7fffffffffffffffLL /* max signed quad */
-#define QUAD_MIN (-0x7fffffffffffffffLL-1) /* min signed quad */
-
-#endif /* __BSD_VISIBLE */
-
-#define LONGLONG_BIT 64
-#define LONGLONG_MIN (-9223372036854775807LL-1)
-#define LONGLONG_MAX 9223372036854775807LL
-#define ULONGLONG_MAX 18446744073709551615ULL
-
-#endif /* _MACHINE_LIMITS_H_ */
diff --git a/libc/arch-x86/string/cache.h b/libc/arch-x86/string/cache.h
index d9aff5c..9d0a563 100644
--- a/libc/arch-x86/string/cache.h
+++ b/libc/arch-x86/string/cache.h
@@ -28,8 +28,15 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#if defined(__slm__)
+/* Values are optimized for Silvermont */
+#define SHARED_CACHE_SIZE (1024*1024) /* Silvermont L2 Cache */
+#define DATA_CACHE_SIZE (24*1024) /* Silvermont L1 Data Cache */
+#else
/* Values are optimized for Atom */
#define SHARED_CACHE_SIZE (512*1024) /* Atom L2 Cache */
#define DATA_CACHE_SIZE (24*1024) /* Atom L1 Data Cache */
+#endif
+
#define SHARED_CACHE_SIZE_HALF (SHARED_CACHE_SIZE / 2)
#define DATA_CACHE_SIZE_HALF (DATA_CACHE_SIZE / 2)
diff --git a/libc/arch-x86_64/include/machine/limits.h b/libc/arch-x86_64/include/machine/limits.h
deleted file mode 100644
index a8c4a88..0000000
--- a/libc/arch-x86_64/include/machine/limits.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/* $OpenBSD: limits.h,v 1.5 2009/11/27 19:54:35 guenther Exp $ */
-
-/*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University 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 THE REGENTS 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 REGENTS 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.
- *
- * @(#)limits.h 7.2 (Berkeley) 6/28/90
- */
-
-#ifndef _MACHINE_LIMITS_H_
-#define _MACHINE_LIMITS_H_
-
-#include <sys/cdefs.h>
-
-#if __POSIX_VISIBLE || __XPG_VISIBLE
-#ifndef SIZE_MAX
-#define SIZE_MAX ULONG_MAX /* max value for a size_t */
-#endif
-#define SSIZE_MAX LONG_MAX /* max value for a ssize_t */
-#endif
-
-#if __BSD_VISIBLE
-#define SIZE_T_MAX ULONG_MAX /* max value for a size_t (historic) */
-
-#define UQUAD_MAX 0xffffffffffffffffULL /* max unsigned quad */
-#define QUAD_MAX 0x7fffffffffffffffLL /* max signed quad */
-#define QUAD_MIN (-0x7fffffffffffffffLL-1) /* min signed quad */
-
-#endif /* __BSD_VISIBLE */
-
-#endif /* _MACHINE_LIMITS_H_ */
diff --git a/libc/bionic/malloc_debug_common.cpp b/libc/bionic/malloc_debug_common.cpp
index 85f7791..4fa4b6e 100644
--- a/libc/bionic/malloc_debug_common.cpp
+++ b/libc/bionic/malloc_debug_common.cpp
@@ -379,7 +379,7 @@
if (gMallocDebugBacklog == 0) {
gMallocDebugBacklog = BACKLOG_DEFAULT_LEN;
}
- so_name = "/system/lib/libc_malloc_debug_leak.so";
+ so_name = "libc_malloc_debug_leak.so";
break;
}
case 20:
@@ -395,7 +395,7 @@
__progname);
return;
}
- so_name = "/system/lib/libc_malloc_debug_qemu.so";
+ so_name = "libc_malloc_debug_qemu.so";
break;
default:
error_log("%s: Debug level %d is unknown\n", __progname, gMallocDebugLevel);
diff --git a/libc/include/limits.h b/libc/include/limits.h
index 471d380..a70021a 100644
--- a/libc/include/limits.h
+++ b/libc/include/limits.h
@@ -105,6 +105,15 @@
#define ULONG_LONG_MAX ULLONG_MAX
#endif
+/* BSD compatibility definitions. */
+#if __BSD_VISIBLE
+#define SIZE_T_MAX ULONG_MAX
+#endif /* __BSD_VISIBLE */
+
+#define SSIZE_MAX LONG_MAX
+
+#define MB_LEN_MAX 1 /* No multibyte characters. */
+
/* New code should use sysconf(_SC_PAGE_SIZE) instead. */
#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
diff --git a/libc/include/search.h b/libc/include/search.h
index 1301a08..b2c0e6b 100644
--- a/libc/include/search.h
+++ b/libc/include/search.h
@@ -10,29 +10,34 @@
#define _SEARCH_H_
#include <sys/cdefs.h>
+#include <sys/types.h>
-typedef enum {
- preorder,
- postorder,
- endorder,
- leaf
+typedef enum {
+ preorder,
+ postorder,
+ endorder,
+ leaf
} VISIT;
#ifdef _SEARCH_PRIVATE
-typedef struct node {
- char *key;
- struct node *llink, *rlink;
+typedef struct node {
+ char* key;
+ struct node* llink;
+ struct node* rlink;
} node_t;
#endif
__BEGIN_DECLS
-void *tdelete(const void * __restrict, void ** __restrict,
- int (*)(const void *, const void *));
-void *tfind(const void *, void * const *,
- int (*)(const void *, const void *));
-void *tsearch(const void *, void **, int (*)(const void *, const void *));
-void twalk(const void *, void (*)(const void *, VISIT, int));
-void tdestroy(void *, void (*)(void *));
+
+void* lfind(const void*, const void*, size_t*, size_t, int (*)(const void*, const void*));
+void* lsearch(const void*, void*, size_t*, size_t, int (*)(const void*, const void*));
+
+void* tdelete(const void* __restrict, void** __restrict, int (*)(const void*, const void*));
+void tdestroy(void*, void (*)(void*));
+void* tfind(const void*, void* const*, int (*)(const void*, const void*));
+void* tsearch(const void*, void**, int (*)(const void*, const void*));
+void twalk(const void*, void (*)(const void*, VISIT, int));
+
__END_DECLS
#endif /* !_SEARCH_H_ */
diff --git a/libc/include/sys/limits.h b/libc/include/sys/limits.h
index 36f73b2..c50eb10 100644
--- a/libc/include/sys/limits.h
+++ b/libc/include/sys/limits.h
@@ -31,9 +31,6 @@
/* Common definitions for limits.h. */
-/* Legacy */
-#include <machine/limits.h>
-
#define CHAR_BIT 8 /* number of bits in a char */
#define SCHAR_MAX 0x7f /* max value for a signed char */
diff --git a/libc/upstream-netbsd/lib/libc/stdlib/lsearch.c b/libc/upstream-netbsd/lib/libc/stdlib/lsearch.c
new file mode 100644
index 0000000..e17130b
--- /dev/null
+++ b/libc/upstream-netbsd/lib/libc/stdlib/lsearch.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Roger L. Snyder.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of the University 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 THE REGENTS 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 REGENTS 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/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)lsearch.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: lsearch.c,v 1.7 2012/06/25 22:32:45 abs Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+#include <search.h>
+
+typedef int (*cmp_fn_t)(const void *, const void *);
+static void *linear_base(const void *, void *, size_t *, size_t,
+ cmp_fn_t, int);
+
+void *
+lsearch(const void *key, void *base, size_t *nelp, size_t width,
+ cmp_fn_t compar)
+{
+
+ _DIAGASSERT(key != NULL);
+ _DIAGASSERT(base != NULL);
+ _DIAGASSERT(compar != NULL);
+
+ return(linear_base(key, base, nelp, width, compar, 1));
+}
+
+void *
+lfind(const void *key, const void *base, size_t *nelp, size_t width,
+ cmp_fn_t compar)
+{
+
+ _DIAGASSERT(key != NULL);
+ _DIAGASSERT(base != NULL);
+ _DIAGASSERT(compar != NULL);
+
+ return(linear_base(key, __UNCONST(base), nelp, width, compar, 0));
+}
+
+static void *
+linear_base(const void *key, void *base, size_t *nelp, size_t width,
+ cmp_fn_t compar, int add_flag)
+{
+ char *element, *end;
+
+ _DIAGASSERT(key != NULL);
+ _DIAGASSERT(base != NULL);
+ _DIAGASSERT(compar != NULL);
+
+ end = (char *)base + *nelp * width;
+ for (element = (char *)base; element < end; element += width)
+ if (!compar(element, key)) /* key found */
+ return element;
+
+ if (!add_flag) /* key not found */
+ return(NULL);
+
+ /*
+ * The UNIX System User's Manual, 1986 edition claims that
+ * a NULL pointer is returned by lsearch with errno set
+ * appropriately, if there is not enough room in the table
+ * to add a new item. This can't be done as none of these
+ * routines have any method of determining the size of the
+ * table. This comment isn't in the 1986-87 System V
+ * manual.
+ */
+ ++*nelp;
+ memcpy(end, key, width);
+ return end;
+}
diff --git a/linker/Android.mk b/linker/Android.mk
index c517a30..f0e6c13 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -1,6 +1,5 @@
-LOCAL_PATH:= $(call my-dir)
+LOCAL_PATH := $(call my-dir)
-LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
diff --git a/tests/sys_select_test.cpp b/tests/sys_select_test.cpp
index 4bb2d18..c1732ee 100644
--- a/tests/sys_select_test.cpp
+++ b/tests/sys_select_test.cpp
@@ -20,6 +20,8 @@
#include <signal.h>
#include <stdlib.h>
#include <sys/select.h>
+#include <sys/types.h>
+#include <sys/wait.h>
TEST(sys_select, fd_set_smoke) {
fd_set fds;
@@ -43,6 +45,32 @@
EXPECT_FALSE(FD_ISSET(1, &fds));
}
+#define DELAY_MSG "1234"
+
+static void DelayedWrite(int* pid, int* fd) {
+ int fds[2];
+ ASSERT_EQ(0, pipe(fds));
+
+ if ((*pid = fork()) == 0) {
+ close(fds[0]);
+ usleep(5000);
+ EXPECT_EQ(5, write(fds[1], DELAY_MSG, sizeof(DELAY_MSG)));
+ close(fds[1]);
+ exit(0);
+ }
+ ASSERT_LT(0, *pid);
+ close(fds[1]);
+
+ *fd = fds[0];
+}
+
+static void DelayedWriteCleanup(int pid, int fd) {
+ char buf[sizeof(DELAY_MSG)];
+ ASSERT_EQ(static_cast<ssize_t>(sizeof(DELAY_MSG)), read(fd, buf, sizeof(DELAY_MSG)));
+ ASSERT_STREQ(DELAY_MSG, buf);
+ ASSERT_EQ(pid, waitpid(pid, NULL, 0));
+}
+
TEST(sys_select, select_smoke) {
fd_set r;
FD_ZERO(&r);
@@ -72,8 +100,17 @@
// Valid timeout...
tv.tv_sec = 1;
- ASSERT_EQ(2, select(max, &r, &w, &e, &tv));
- ASSERT_NE(0, tv.tv_usec); // ...which got updated.
+ int pid, fd;
+ DelayedWrite(&pid, &fd);
+
+ FD_ZERO(&r);
+ FD_SET(fd, &r);
+ ASSERT_EQ(1, select(fd+1, &r, NULL, NULL, &tv));
+ // Both tv_sec and tv_nsec should have been updated.
+ ASSERT_EQ(0, tv.tv_sec);
+ ASSERT_NE(0, tv.tv_usec);
+
+ DelayedWriteCleanup(pid, fd);
}
TEST(sys_select, pselect_smoke) {
@@ -109,6 +146,15 @@
// Valid timeout...
tv.tv_sec = 1;
- ASSERT_EQ(2, pselect(max, &r, &w, &e, &tv, &ss));
- ASSERT_EQ(0, tv.tv_nsec); // ...which did _not_ get updated.
+ int pid, fd;
+ DelayedWrite(&pid, &fd);
+
+ FD_ZERO(&r);
+ FD_SET(fd, &r);
+ ASSERT_EQ(1, pselect(fd+1, &r, NULL, NULL, &tv, NULL));
+ // Neither tv_sec nor tv_nsec should have been updated.
+ ASSERT_EQ(1, tv.tv_sec);
+ ASSERT_EQ(0, tv.tv_nsec);
+
+ DelayedWriteCleanup(pid, fd);
}