Merge "Replace fmemopen."
diff --git a/README.md b/README.md
index ee83b08..cb9c454 100644
--- a/README.md
+++ b/README.md
@@ -171,6 +171,10 @@
contents for external/kernel-headers/.
2. Run update_all.py to scrub those headers and import them into bionic.
+Note that if you're actually just trying to expose device-specific headers to
+build your device drivers, you shouldn't modify bionic. Instead use
+`TARGET_DEVICE_KERNEL_HEADERS` and friends described in [config.mk](https://android.googlesource.com/platform/build/+/master/core/config.mk#186).
+
Updating tzdata
---------------
diff --git a/libc/Android.bp b/libc/Android.bp
index b8ecf95..842dae4 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -238,9 +238,11 @@
"upstream-freebsd/lib/libc/string/wcspbrk.c",
"upstream-freebsd/lib/libc/string/wcsrchr.c",
"upstream-freebsd/lib/libc/string/wcsspn.c",
+ "upstream-freebsd/lib/libc/string/wcsstr.c",
"upstream-freebsd/lib/libc/string/wcstok.c",
"upstream-freebsd/lib/libc/string/wmemchr.c",
"upstream-freebsd/lib/libc/string/wmemcmp.c",
+ "upstream-freebsd/lib/libc/string/wmemcpy.c",
"upstream-freebsd/lib/libc/string/wmemmove.c",
"upstream-freebsd/lib/libc/string/wmemset.c",
],
@@ -386,7 +388,6 @@
name: "libc_openbsd_ndk",
defaults: ["libc_defaults"],
srcs: [
- "upstream-openbsd/lib/libc/compat-43/killpg.c",
"upstream-openbsd/lib/libc/gen/alarm.c",
"upstream-openbsd/lib/libc/gen/ctype_.c",
"upstream-openbsd/lib/libc/gen/daemon.c",
@@ -501,9 +502,7 @@
"upstream-openbsd/lib/libc/string/strspn.c",
"upstream-openbsd/lib/libc/string/strstr.c",
"upstream-openbsd/lib/libc/string/strtok.c",
- "upstream-openbsd/lib/libc/string/wmemcpy.c",
"upstream-openbsd/lib/libc/string/wcslcpy.c",
- "upstream-openbsd/lib/libc/string/wcsstr.c",
"upstream-openbsd/lib/libc/string/wcswidth.c",
],
@@ -1396,6 +1395,7 @@
"bionic/ifaddrs.cpp",
"bionic/inotify_init.cpp",
"bionic/ioctl.cpp",
+ "bionic/killpg.cpp",
"bionic/langinfo.cpp",
"bionic/lchown.cpp",
"bionic/lfs64_support.cpp",
diff --git a/libc/bionic/getcwd.cpp b/libc/bionic/getcwd.cpp
index c2a7e23..50487ec 100644
--- a/libc/bionic/getcwd.cpp
+++ b/libc/bionic/getcwd.cpp
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#undef _FORTIFY_SOURCE
#include <errno.h>
#include <malloc.h>
#include <string.h>
diff --git a/libc/bionic/killpg.cpp b/libc/bionic/killpg.cpp
new file mode 100644
index 0000000..01a58b3
--- /dev/null
+++ b/libc/bionic/killpg.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2017 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>
+
+int killpg(pid_t pgrp, int sig) {
+ if (pgrp < 0) {
+ errno = EINVAL;
+ return -1;
+ }
+ return kill(-pgrp, sig);
+}
diff --git a/libc/bionic/poll.cpp b/libc/bionic/poll.cpp
index eded56a..dbc9584 100644
--- a/libc/bionic/poll.cpp
+++ b/libc/bionic/poll.cpp
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#undef _FORTIFY_SOURCE
#include <errno.h>
#include <sys/poll.h>
#include <sys/select.h>
diff --git a/libc/bionic/readlink.cpp b/libc/bionic/readlink.cpp
index a53f933..3bb7bc1 100644
--- a/libc/bionic/readlink.cpp
+++ b/libc/bionic/readlink.cpp
@@ -26,8 +26,6 @@
* SUCH DAMAGE.
*/
-#undef _FORTIFY_SOURCE
-
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
diff --git a/libc/bionic/recv.cpp b/libc/bionic/recv.cpp
index 061cd46..60f264d 100644
--- a/libc/bionic/recv.cpp
+++ b/libc/bionic/recv.cpp
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#undef _FORTIFY_SOURCE
#include <sys/socket.h>
ssize_t recv(int socket, void *buf, size_t len, int flags) {
diff --git a/libc/bionic/strchr.cpp b/libc/bionic/strchr.cpp
index 5bd3f19..fd8a924 100644
--- a/libc/bionic/strchr.cpp
+++ b/libc/bionic/strchr.cpp
@@ -27,7 +27,6 @@
* SUCH DAMAGE.
*/
-#undef _FORTIFY_SOURCE
#include <string.h>
char* strchr(const char* p, int ch) {
diff --git a/libc/bionic/strrchr.cpp b/libc/bionic/strrchr.cpp
index 3fdb47c..b6c40f4 100644
--- a/libc/bionic/strrchr.cpp
+++ b/libc/bionic/strrchr.cpp
@@ -27,7 +27,6 @@
* SUCH DAMAGE.
*/
-#undef _FORTIFY_SOURCE
#include <string.h>
char* strrchr(const char* p, int ch) {
diff --git a/libc/include/bits/lockf.h b/libc/include/bits/lockf.h
index c24f18b..a8e273e 100644
--- a/libc/include/bits/lockf.h
+++ b/libc/include/bits/lockf.h
@@ -39,11 +39,7 @@
__BEGIN_DECLS
-#if defined(__USE_FILE_OFFSET64)
-int lockf(int, int, off_t) __RENAME(lockf64) __INTRODUCED_IN(24);
-#else
-int lockf(int, int, off_t) __INTRODUCED_IN(24);
-#endif
+int lockf(int, int, off_t) __RENAME_IF_FILE_OFFSET64(lockf64) __INTRODUCED_IN(24);
int lockf64(int, int, off64_t) __INTRODUCED_IN(24);
__END_DECLS
diff --git a/libc/include/fcntl.h b/libc/include/fcntl.h
index c98022c..f27efdf 100644
--- a/libc/include/fcntl.h
+++ b/libc/include/fcntl.h
@@ -71,8 +71,7 @@
int creat(const char*, mode_t);
int creat64(const char*, mode_t) __INTRODUCED_IN(21);
-int openat(int, const char*, int, ...) __overloadable
- __RENAME_CLANG(openat);
+int openat(int, const char*, int, ...) __overloadable __RENAME_CLANG(openat);
int openat64(int, const char*, int, ...) __INTRODUCED_IN(21);
int open(const char*, int, ...) __overloadable __RENAME_CLANG(open);
int open64(const char*, int, ...) __INTRODUCED_IN(21);
@@ -80,17 +79,11 @@
ssize_t tee(int, int, size_t, unsigned int) __INTRODUCED_IN(21);
ssize_t vmsplice(int, const struct iovec*, size_t, unsigned int) __INTRODUCED_IN(21);
-#if defined(__USE_FILE_OFFSET64)
-int fallocate(int, int, off_t, off_t) __RENAME(fallocate64) __INTRODUCED_IN(21);
-int posix_fadvise(int, off_t, off_t, int) __RENAME(posix_fadvise64) __INTRODUCED_IN(21);
-int posix_fallocate(int, off_t, off_t) __RENAME(posix_fallocate64) __INTRODUCED_IN(21);
-#else
-int fallocate(int, int, off_t, off_t) __INTRODUCED_IN(21);
-int posix_fadvise(int, off_t, off_t, int) __INTRODUCED_IN(21);
-int posix_fallocate(int, off_t, off_t) __INTRODUCED_IN(21);
-#endif
+int fallocate(int, int, off_t, off_t) __RENAME_IF_FILE_OFFSET64(fallocate64) __INTRODUCED_IN(21);
int fallocate64(int, int, off64_t, off64_t) __INTRODUCED_IN(21);
+int posix_fadvise(int, off_t, off_t, int) __RENAME_IF_FILE_OFFSET64(posix_fadvise64) __INTRODUCED_IN(21);
int posix_fadvise64(int, off64_t, off64_t, int) __INTRODUCED_IN(21);
+int posix_fallocate(int, off_t, off_t) __RENAME_IF_FILE_OFFSET64(posix_fallocate64) __INTRODUCED_IN(21);
int posix_fallocate64(int, off64_t, off64_t) __INTRODUCED_IN(21);
#if defined(__USE_GNU)
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index 307545c..dd5b345 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -237,6 +237,11 @@
/* _FILE_OFFSET_BITS 64 support. */
#if !defined(__LP64__) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
#define __USE_FILE_OFFSET64 1
+/*
+ * Note that __RENAME_IF_FILE_OFFSET64 is only valid if the off_t and off64_t
+ * functions were both added at the same API level because if you use this,
+ * you only have one declaration to attach __INTRODUCED_IN to.
+ */
#define __RENAME_IF_FILE_OFFSET64(func) __RENAME(func)
#else
#define __RENAME_IF_FILE_OFFSET64(func)
diff --git a/libc/include/sys/uio.h b/libc/include/sys/uio.h
index 2611774..b166277 100644
--- a/libc/include/sys/uio.h
+++ b/libc/include/sys/uio.h
@@ -38,13 +38,8 @@
ssize_t writev(int, const struct iovec*, int);
#if defined(__USE_GNU)
-#if defined(__USE_FILE_OFFSET64)
-ssize_t preadv(int, const struct iovec*, int, off_t) __RENAME(preadv64) __INTRODUCED_IN(24);
-ssize_t pwritev(int, const struct iovec*, int, off_t) __RENAME(pwritev64) __INTRODUCED_IN(24);
-#else
-ssize_t preadv(int, const struct iovec*, int, off_t) __INTRODUCED_IN(24);
-ssize_t pwritev(int, const struct iovec*, int, off_t) __INTRODUCED_IN(24);
-#endif
+ssize_t preadv(int, const struct iovec*, int, off_t) __RENAME_IF_FILE_OFFSET64(preadv64) __INTRODUCED_IN(24);
+ssize_t pwritev(int, const struct iovec*, int, off_t) __RENAME_IF_FILE_OFFSET64(pwritev64) __INTRODUCED_IN(24);
ssize_t preadv64(int, const struct iovec*, int, off64_t) __INTRODUCED_IN(24);
ssize_t pwritev64(int, const struct iovec*, int, off64_t) __INTRODUCED_IN(24);
#endif
diff --git a/libc/upstream-openbsd/lib/libc/compat-43/killpg.c b/libc/upstream-freebsd/lib/libc/string/wcsstr.c
similarity index 65%
rename from libc/upstream-openbsd/lib/libc/compat-43/killpg.c
rename to libc/upstream-freebsd/lib/libc/string/wcsstr.c
index 75b1ad9..ce598a6 100644
--- a/libc/upstream-openbsd/lib/libc/compat-43/killpg.c
+++ b/libc/upstream-freebsd/lib/libc/string/wcsstr.c
@@ -1,6 +1,9 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -27,19 +30,34 @@
* SUCH DAMAGE.
*/
-#include <sys/types.h>
-#include <signal.h>
-#include <errno.h>
+#if 0
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)strstr.c 8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <wchar.h>
/*
- * Backwards-compatible killpg().
+ * Find the first occurrence of find in s.
*/
-int
-killpg(pid_t pgid, int sig)
+wchar_t *
+wcsstr(const wchar_t * __restrict s, const wchar_t * __restrict find)
{
- if (pgid == 1) {
- errno = ESRCH;
- return (-1);
+ wchar_t c, sc;
+ size_t len;
+
+ if ((c = *find++) != L'\0') {
+ len = wcslen(find);
+ do {
+ do {
+ if ((sc = *s++) == L'\0')
+ return (NULL);
+ } while (sc != c);
+ } while (wcsncmp(s, find, len) != 0);
+ s--;
}
- return (kill(-pgid, sig));
+ return ((wchar_t *)s);
}
diff --git a/libc/upstream-openbsd/lib/libc/string/wmemcpy.c b/libc/upstream-freebsd/lib/libc/string/wmemcpy.c
similarity index 84%
rename from libc/upstream-openbsd/lib/libc/string/wmemcpy.c
rename to libc/upstream-freebsd/lib/libc/string/wmemcpy.c
index cf02ab9..c10770c 100644
--- a/libc/upstream-openbsd/lib/libc/string/wmemcpy.c
+++ b/libc/upstream-freebsd/lib/libc/string/wmemcpy.c
@@ -1,6 +1,3 @@
-/* $OpenBSD: wmemcpy.c,v 1.4 2015/09/12 16:23:14 guenther Exp $ */
-/* $NetBSD: wmemcpy.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */
-
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
@@ -29,13 +26,19 @@
* citrus Id: wmemcpy.c,v 1.2 2000/12/20 14:08:31 itojun Exp
*/
+#include <sys/cdefs.h>
+#if 0
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: wmemcpy.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
+#endif /* LIBC_SCCS and not lint */
+#endif
+__FBSDID("$FreeBSD$");
+
#include <string.h>
#include <wchar.h>
wchar_t *
-wmemcpy(wchar_t *d, const wchar_t *s, size_t n)
+wmemcpy(wchar_t * __restrict d, const wchar_t * __restrict s, size_t n)
{
-
return (wchar_t *)memcpy(d, s, n * sizeof(wchar_t));
}
-DEF_STRONG(wmemcpy);
diff --git a/libc/upstream-openbsd/android/include/openbsd-compat.h b/libc/upstream-openbsd/android/include/openbsd-compat.h
index 9b16da7..baf5057 100644
--- a/libc/upstream-openbsd/android/include/openbsd-compat.h
+++ b/libc/upstream-openbsd/android/include/openbsd-compat.h
@@ -40,6 +40,7 @@
/* Ignore all DEF_STRONG/DEF_WEAK in OpenBSD. */
#define DEF_STRONG(sym)
#define DEF_WEAK(sym)
+#define __weak_alias __strong_alias
/* Ignore all __warn_references in OpenBSD. */
#define __warn_references(sym,msg)
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/strtoimax.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoimax.c
index 2fc04e4..74e3556 100644
--- a/libc/upstream-openbsd/lib/libc/stdlib/strtoimax.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoimax.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: strtoimax.c,v 1.2 2014/09/13 20:10:12 schwarze Exp $ */
+/* $OpenBSD: strtoimax.c,v 1.4 2017/07/06 16:23:11 millert Exp $ */
/*
* Copyright (c) 1992 The Regents of the University of California.
* All rights reserved.
@@ -74,8 +74,8 @@
if (c == '+')
c = *s++;
}
- if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X')) {
+ if ((base == 0 || base == 16) && c == '0' &&
+ (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) {
c = s[1];
s += 2;
base = 16;
@@ -148,3 +148,4 @@
*endptr = (char *) (any ? s - 1 : nptr);
return (acc);
}
+DEF_STRONG(strtoimax);
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/strtol.c b/libc/upstream-openbsd/lib/libc/stdlib/strtol.c
index 86cec35..599d235 100644
--- a/libc/upstream-openbsd/lib/libc/stdlib/strtol.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtol.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: strtol.c,v 1.10 2014/09/13 20:10:12 schwarze Exp $ */
+/* $OpenBSD: strtol.c,v 1.12 2017/07/06 16:23:11 millert Exp $ */
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -75,8 +75,8 @@
if (c == '+')
c = *s++;
}
- if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X')) {
+ if ((base == 0 || base == 16) && c == '0' &&
+ (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) {
c = s[1];
s += 2;
base = 16;
@@ -148,3 +148,4 @@
*endptr = (char *) (any ? s - 1 : nptr);
return (acc);
}
+DEF_STRONG(strtol);
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/strtoll.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoll.c
index cf82c8e..d21a249 100644
--- a/libc/upstream-openbsd/lib/libc/stdlib/strtoll.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoll.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: strtoll.c,v 1.8 2014/09/13 20:10:12 schwarze Exp $ */
+/* $OpenBSD: strtoll.c,v 1.10 2017/07/06 16:23:11 millert Exp $ */
/*
* Copyright (c) 1992 The Regents of the University of California.
* All rights reserved.
@@ -77,8 +77,8 @@
if (c == '+')
c = *s++;
}
- if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X')) {
+ if ((base == 0 || base == 16) && c == '0' &&
+ (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) {
c = s[1];
s += 2;
base = 16;
@@ -151,5 +151,6 @@
*endptr = (char *) (any ? s - 1 : nptr);
return (acc);
}
+DEF_STRONG(strtoll);
-__strong_alias(strtoq, strtoll);
+__weak_alias(strtoq, strtoll);
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/strtoul.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoul.c
index 2aa41b7..6667bea 100644
--- a/libc/upstream-openbsd/lib/libc/stdlib/strtoul.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoul.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: strtoul.c,v 1.9 2014/09/13 20:10:12 schwarze Exp $ */
+/* $OpenBSD: strtoul.c,v 1.11 2017/07/06 16:23:11 millert Exp $ */
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -69,8 +69,8 @@
if (c == '+')
c = *s++;
}
- if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X')) {
+ if ((base == 0 || base == 16) && c == '0' &&
+ (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) {
c = s[1];
s += 2;
base = 16;
@@ -107,3 +107,4 @@
*endptr = (char *) (any ? s - 1 : nptr);
return (acc);
}
+DEF_STRONG(strtoul);
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/strtoull.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoull.c
index 8464176..d7733e40 100644
--- a/libc/upstream-openbsd/lib/libc/stdlib/strtoull.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoull.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: strtoull.c,v 1.7 2014/09/13 20:10:12 schwarze Exp $ */
+/* $OpenBSD: strtoull.c,v 1.9 2017/07/06 16:23:11 millert Exp $ */
/*
* Copyright (c) 1992 The Regents of the University of California.
* All rights reserved.
@@ -71,8 +71,8 @@
if (c == '+')
c = *s++;
}
- if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X')) {
+ if ((base == 0 || base == 16) && c == '0' &&
+ (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) {
c = s[1];
s += 2;
base = 16;
@@ -109,5 +109,6 @@
*endptr = (char *) (any ? s - 1 : nptr);
return (acc);
}
+DEF_STRONG(strtoull);
-__strong_alias(strtouq, strtoull);
+__weak_alias(strtouq, strtoull);
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/strtoumax.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoumax.c
index c73f7e5..348184c 100644
--- a/libc/upstream-openbsd/lib/libc/stdlib/strtoumax.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoumax.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: strtoumax.c,v 1.2 2014/09/13 20:10:12 schwarze Exp $ */
+/* $OpenBSD: strtoumax.c,v 1.4 2017/07/06 16:23:11 millert Exp $ */
/*
* Copyright (c) 1992 The Regents of the University of California.
* All rights reserved.
@@ -68,8 +68,8 @@
if (c == '+')
c = *s++;
}
- if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X')) {
+ if ((base == 0 || base == 16) && c == '0' &&
+ (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) {
c = s[1];
s += 2;
base = 16;
@@ -106,3 +106,4 @@
*endptr = (char *) (any ? s - 1 : nptr);
return (acc);
}
+DEF_STRONG(strtoumax);
diff --git a/libc/upstream-openbsd/lib/libc/string/wcsstr.c b/libc/upstream-openbsd/lib/libc/string/wcsstr.c
deleted file mode 100644
index 6a7b0da..0000000
--- a/libc/upstream-openbsd/lib/libc/string/wcsstr.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/* $OpenBSD: wcsstr.c,v 1.5 2015/10/01 02:32:07 guenther Exp $ */
-/* $NetBSD: wcsstr.c,v 1.3 2003/03/05 20:18:17 tshiozak Exp $ */
-
-/*-
- * Copyright (c)1999 Citrus 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:
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
- *
- * citrus Id: wcsstr.c,v 1.2 2000/12/21 05:07:25 itojun Exp
- */
-
-#include <wchar.h>
-
-wchar_t *
-#ifdef WCSWCS
-wcswcs(const wchar_t *big, const wchar_t *little)
-#else
-wcsstr(const wchar_t *big, const wchar_t *little)
-#endif
-{
- const wchar_t *p;
- const wchar_t *q;
- const wchar_t *r;
-
- if (!*little) {
- return (wchar_t *)big;
- }
- if (wcslen(big) < wcslen(little))
- return NULL;
-
- p = big;
- q = little;
- while (*p) {
- q = little;
- r = p;
- while (*q) {
- if (*r != *q)
- break;
- q++;
- r++;
- }
- if (!*q) {
- return (wchar_t *)p;
- }
- p++;
- }
- return NULL;
-}
-#ifndef WCSWCS
-DEF_STRONG(wcsstr);
-#endif
diff --git a/tests/signal_test.cpp b/tests/signal_test.cpp
index 36ac690..207c156 100644
--- a/tests/signal_test.cpp
+++ b/tests/signal_test.cpp
@@ -527,3 +527,11 @@
ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set));
EXPECT_TRUE(sigismember(&set, SIGALRM));
}
+
+TEST(signal, killpg_EINVAL) {
+ // POSIX leaves pgrp <= 1 undefined, but glibc fails with EINVAL for < 0
+ // and passes 0 through to kill(2).
+ errno = 0;
+ ASSERT_EQ(-1, killpg(-1, SIGKILL));
+ ASSERT_EQ(EINVAL, errno);
+}
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index 4c4c102..c724f74 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -555,54 +555,6 @@
close(fd);
}
-TEST(stdlib, strtol_EINVAL) {
- errno = 0;
- strtol("123", NULL, -1);
- ASSERT_EQ(EINVAL, errno);
- errno = 0;
- strtol("123", NULL, 1);
- ASSERT_EQ(EINVAL, errno);
- errno = 0;
- strtol("123", NULL, 37);
- ASSERT_EQ(EINVAL, errno);
-}
-
-TEST(stdlib, strtoll_EINVAL) {
- errno = 0;
- strtoll("123", NULL, -1);
- ASSERT_EQ(EINVAL, errno);
- errno = 0;
- strtoll("123", NULL, 1);
- ASSERT_EQ(EINVAL, errno);
- errno = 0;
- strtoll("123", NULL, 37);
- ASSERT_EQ(EINVAL, errno);
-}
-
-TEST(stdlib, strtoul_EINVAL) {
- errno = 0;
- strtoul("123", NULL, -1);
- ASSERT_EQ(EINVAL, errno);
- errno = 0;
- strtoul("123", NULL, 1);
- ASSERT_EQ(EINVAL, errno);
- errno = 0;
- strtoul("123", NULL, 37);
- ASSERT_EQ(EINVAL, errno);
-}
-
-TEST(stdlib, strtoull_EINVAL) {
- errno = 0;
- strtoull("123", NULL, -1);
- ASSERT_EQ(EINVAL, errno);
- errno = 0;
- strtoull("123", NULL, 1);
- ASSERT_EQ(EINVAL, errno);
- errno = 0;
- strtoull("123", NULL, 37);
- ASSERT_EQ(EINVAL, errno);
-}
-
TEST(stdlib, getsubopt) {
char* const tokens[] = {
const_cast<char*>("a"),
@@ -648,3 +600,51 @@
// "mblen() shall ... return 0 (if s points to the null byte)".
EXPECT_EQ(0, mblen("", 1));
}
+
+template <typename T>
+static void CheckStrToInt(T fn(const char* s, char** end, int base)) {
+ char* end_p;
+
+ // Negative base => invalid.
+ errno = 0;
+ ASSERT_EQ(T(0), fn("123", &end_p, -1));
+ ASSERT_EQ(EINVAL, errno);
+
+ // Base 1 => invalid (base 0 means "please guess").
+ errno = 0;
+ ASSERT_EQ(T(0), fn("123", &end_p, 1));
+ ASSERT_EQ(EINVAL, errno);
+
+ // Base > 36 => invalid.
+ errno = 0;
+ ASSERT_EQ(T(0), fn("123", &end_p, 37));
+ ASSERT_EQ(EINVAL, errno);
+
+ // If we see "0x" *not* followed by a hex digit, we shouldn't swallow the 'x'.
+ ASSERT_EQ(T(0), fn("0xy", &end_p, 16));
+ ASSERT_EQ('x', *end_p);
+}
+
+TEST(stdlib, strtol_smoke) {
+ CheckStrToInt(strtol);
+}
+
+TEST(stdlib, strtoll_smoke) {
+ CheckStrToInt(strtoll);
+}
+
+TEST(stdlib, strtoul_smoke) {
+ CheckStrToInt(strtoul);
+}
+
+TEST(stdlib, strtoull_smoke) {
+ CheckStrToInt(strtoull);
+}
+
+TEST(stdlib, strtoimax_smoke) {
+ CheckStrToInt(strtoimax);
+}
+
+TEST(stdlib, strtoumax_smoke) {
+ CheckStrToInt(strtoumax);
+}