libc/Android.bp: more cleanup.
These files were segregated because they were lacking a little cleanup.
Unfortunately that means this change has to do some of the cleanup, but
that's probably for the best.
Test: treehugger
Change-Id: I2dd33504787fc3313995de99e0745a0df22915b3
diff --git a/libc/Android.bp b/libc/Android.bp
index 5afed1a..1047891 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -20,31 +20,6 @@
],
}
-libc_common_src_files = [
- "bionic/ether_aton.c",
- "bionic/ether_ntoa.c",
- "bionic/exit.cpp",
- "bionic/initgroups.c",
- "bionic/isatty.c",
- "bionic/sched_cpualloc.c",
- "bionic/sched_cpucount.c",
- "bionic/sysprop_helpers.cpp",
- "stdio/fmemopen.cpp",
- "stdio/parsefloat.c",
- "stdio/refill.c",
- "stdio/stdio.cpp",
- "stdio/stdio_ext.cpp",
- "stdio/vfscanf.cpp",
- "stdio/vfwscanf.cpp",
-]
-
-// off64_t/time64_t support on LP32.
-// ========================================================
-libc_common_src_files_32 = [
- "bionic/legacy_32_bit_support.cpp",
- "bionic/time64.c",
-]
-
libc_common_flags = [
"-D_LIBC=1",
"-D__BIONIC_LP32_USE_STAT64",
@@ -844,9 +819,12 @@
"bionic/dup.cpp",
"bionic/environ.cpp",
"bionic/error.cpp",
+ "bionic/ether_aton.c",
+ "bionic/ether_ntoa.c",
"bionic/eventfd.cpp",
"bionic/exec.cpp",
"bionic/execinfo.cpp",
+ "bionic/exit.cpp",
"bionic/faccessat.cpp",
"bionic/fchmod.cpp",
"bionic/fchmodat.cpp",
@@ -879,8 +857,10 @@
"bionic/iconv.cpp",
"bionic/icu_wrappers.cpp",
"bionic/ifaddrs.cpp",
+ "bionic/initgroups.c",
"bionic/inotify_init.cpp",
"bionic/ioctl.cpp",
+ "bionic/isatty.c",
"bionic/killpg.cpp",
"bionic/langinfo.cpp",
"bionic/lchown.cpp",
@@ -951,6 +931,8 @@
"bionic/rename.cpp",
"bionic/rmdir.cpp",
"bionic/scandir.cpp",
+ "bionic/sched_cpualloc.c",
+ "bionic/sched_cpucount.c",
"bionic/sched_getaffinity.cpp",
"bionic/sched_getcpu.cpp",
"bionic/semaphore.cpp",
@@ -988,6 +970,7 @@
"bionic/sys_time.cpp",
"bionic/sysinfo.cpp",
"bionic/syslog.cpp",
+ "bionic/sysprop_helpers.cpp",
"bionic/system.cpp",
"bionic/system_property_api.cpp",
"bionic/system_property_set.cpp",
@@ -1011,6 +994,16 @@
"bionic/wcwidth.cpp",
"bionic/wmempcpy.cpp",
+ // Forked but not yet cleaned up/rewritten stdio code.
+ // TODO: finish cleanup.
+ "stdio/fmemopen.cpp",
+ "stdio/parsefloat.c",
+ "stdio/refill.c",
+ "stdio/stdio.cpp",
+ "stdio/stdio_ext.cpp",
+ "stdio/vfscanf.cpp",
+ "stdio/vfwscanf.cpp",
+
// TODO: why isn't this in a static-libc-only module?
// This contains a weak stub implementation of __find_icu_symbol for wctype.cpp,
// which will be overridden by the actual one in libc.so.
@@ -1223,10 +1216,16 @@
},
},
- // TODO: move to libc/bionic/legacy_32_bit_support.cpp or #if __LP64__ instead.
multilib: {
lib32: {
- srcs: ["bionic/mmap.cpp"],
+ srcs: [
+ // off64_t/time64_t support on LP32.
+ "bionic/legacy_32_bit_support.cpp",
+ "bionic/time64.c",
+
+ // TODO: move to libc/bionic/legacy_32_bit_support.cpp or #if __LP64__ instead.
+ "bionic/mmap.cpp",
+ ],
},
},
@@ -1336,20 +1335,13 @@
}
// ========================================================
-// libc_common.a
+// libc_common.a --- everything shared by libc.a and libc.so
// ========================================================
cc_library_static {
defaults: ["libc_defaults"],
name: "libc_common",
- srcs: libc_common_src_files,
- multilib: {
- lib32: {
- srcs: libc_common_src_files_32,
- },
- },
-
whole_static_libs: [
"libarm-optimized-routines-string",
"libasync_safe",
@@ -1377,7 +1369,7 @@
}
// ========================================================
-// libc_static_dispatch.a
+// libc_static_dispatch.a --- libc.a ifuncs
// ========================================================
cc_library_static {
defaults: ["libc_defaults"],
@@ -1403,7 +1395,7 @@
}
// ========================================================
-// libc_dynamic_dispatch.a
+// libc_dynamic_dispatch.a --- libc.so ifuncs
// ========================================================
cc_library_static {
defaults: ["libc_defaults"],
diff --git a/libc/private/bsd_sys_param.h b/libc/private/bsd_sys_param.h
index be5f692..ab54aa0 100644
--- a/libc/private/bsd_sys_param.h
+++ b/libc/private/bsd_sys_param.h
@@ -20,4 +20,4 @@
/* OpenBSD has these in <sys/param.h>, but "ALIGN" isn't something we want to reserve. */
#define ALIGNBYTES (sizeof(uintptr_t) - 1)
-#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES)
+#define ALIGN(p) ((__BIONIC_CAST(reinterpret_cast, uintptr_t, p) + ALIGNBYTES) & ~ALIGNBYTES)
diff --git a/libc/stdio/local.h b/libc/stdio/local.h
index a5eb636..62efea1 100644
--- a/libc/stdio/local.h
+++ b/libc/stdio/local.h
@@ -236,7 +236,7 @@
/* OpenBSD exposes these in <stdio.h>, but we only want them exposed to the implementation. */
#define __sferror(p) (((p)->_flags & __SERR) != 0)
#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR | __SEOF)))
-#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
+#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : __BIONIC_CAST(static_cast, int, *(p)->_p++))
/* OpenBSD declares these in fvwrite.h, but we share them with C++ parts of the implementation. */
struct __siov {
@@ -288,7 +288,7 @@
char* __hldtoa(long double, const char*, int, int*, int*, char**);
char* __ldtoa(long double*, int, int, int*, int*, char**);
-#define WCIO_GET(fp) (_EXT(fp) ? &(_EXT(fp)->_wcio) : (struct wchar_io_data*)0)
+#define WCIO_GET(fp) (_EXT(fp) ? &(_EXT(fp)->_wcio) : NULL)
#define ORIENT_BYTES (-1)
#define ORIENT_UNKNOWN 0
diff --git a/libc/stdio/scanf_common.h b/libc/stdio/scanf_common.h
index 8132e90..1b6b87f 100644
--- a/libc/stdio/scanf_common.h
+++ b/libc/stdio/scanf_common.h
@@ -82,7 +82,7 @@
#define CT_FLOAT 4 // Float: strtod
#define to_digit(c) static_cast<int>((c) - '0')
-#define is_digit(c) ((unsigned)to_digit(c) <= 9)
+#define is_digit(c) (static_cast<unsigned>(to_digit(c)) <= 9)
// Append a digit to a value and check for overflow.
#define APPEND_DIGIT(val, dig) \
@@ -112,4 +112,4 @@
__fortify_fatal("%%w%s%d is unsupported", fast ? "f" : "", size);
}
-#pragma clang diagnostic pop
\ No newline at end of file
+#pragma clang diagnostic pop
diff --git a/libc/stdio/vfscanf.cpp b/libc/stdio/vfscanf.cpp
index 3607995..92ff541 100644
--- a/libc/stdio/vfscanf.cpp
+++ b/libc/stdio/vfscanf.cpp
@@ -629,10 +629,10 @@
* as `[-+]0`.
*/
if (flags & NDIGITS) {
- if (p > buf) (void)ungetc(*(u_char*)--p, fp);
+ if (p > buf) ungetc(*reinterpret_cast<u_char*>(--p), fp);
goto match_failure;
}
- c = ((u_char*)p)[-1];
+ c = reinterpret_cast<u_char*>(p)[-1];
if ((base == 2 && (c == 'b' || c == 'B')) || c == 'x' || c == 'X') {
--p;
(void)ungetc(c, fp);
@@ -647,7 +647,7 @@
res = strtoimax(buf, nullptr, base);
}
if (flags & POINTER) {
- *va_arg(ap, void**) = (void*)(uintptr_t)res;
+ *va_arg(ap, void**) = reinterpret_cast<void*>(res);
} else if (flags & MAXINT) {
*va_arg(ap, intmax_t*) = res;
} else if (flags & LLONG) {
@@ -685,7 +685,7 @@
float res = strtof(buf, &p);
*va_arg(ap, float*) = res;
}
- if ((size_t)(p - buf) != width) abort();
+ if (static_cast<size_t>(p - buf) != width) abort();
nassigned++;
}
nread += width;
diff --git a/libc/stdio/vfwscanf.cpp b/libc/stdio/vfwscanf.cpp
index 3df4a87..21d1783 100644
--- a/libc/stdio/vfwscanf.cpp
+++ b/libc/stdio/vfwscanf.cpp
@@ -32,6 +32,7 @@
*/
#include "scanf_common.h"
+
// An interpretive version of __sccl from vfscanf.c --- a table of all wchar_t values would
// be a little too expensive, and some kind of compressed version isn't worth the trouble.
static inline bool in_ccl(wchar_t wc, const wchar_t* ccl) {
@@ -335,7 +336,7 @@
if (!(flags & SUPPRESS)) p = va_arg(ap, wchar_t*);
n = 0;
while (width-- != 0 && (wi = __fgetwc_unlock(fp)) != WEOF) {
- if (!(flags & SUPPRESS)) *p++ = (wchar_t)wi;
+ if (!(flags & SUPPRESS)) *p++ = static_cast<wchar_t>(wi);
n++;
}
if (n == 0) goto input_failure;
@@ -348,10 +349,10 @@
while (width != 0 && (wi = __fgetwc_unlock(fp)) != WEOF) {
if (width >= MB_CUR_MAX && !(flags & SUPPRESS)) {
nconv = wcrtomb(mbp, wi, &mbs);
- if (nconv == (size_t)-1) goto input_failure;
+ if (nconv == static_cast<size_t>(-1)) goto input_failure;
} else {
nconv = wcrtomb(mbbuf, wi, &mbs);
- if (nconv == (size_t)-1) goto input_failure;
+ if (nconv == static_cast<size_t>(-1)) goto input_failure;
if (nconv > width) {
__ungetwc(wi, fp);
break;
@@ -373,7 +374,7 @@
case CT_STRING:
// CT_CCL: scan a (nonempty) character class (sets NOSKIP).
// CT_STRING: like CCL, but zero-length string OK, & no NOSKIP.
- if (width == 0) width = (size_t)~0; // 'infinity'.
+ if (width == 0) width = SIZE_MAX; // 'infinity'.
if ((flags & SUPPRESS) && (flags & LONG)) {
n = 0;
while ((wi = __fgetwc_unlock(fp)) != WEOF && width-- != 0 && ((c == CT_CCL && in_ccl(wi, ccl)) || (c == CT_STRING && !iswspace(wi)))) n++;
@@ -381,7 +382,7 @@
} else if (flags & LONG) {
p0 = p = va_arg(ap, wchar_t*);
while ((wi = __fgetwc_unlock(fp)) != WEOF && width-- != 0 && ((c == CT_CCL && in_ccl(wi, ccl)) || (c == CT_STRING && !iswspace(wi)))) {
- *p++ = (wchar_t)wi;
+ *p++ = static_cast<wchar_t>(wi);
}
if (wi != WEOF) __ungetwc(wi, fp);
n = p - p0;
@@ -392,10 +393,10 @@
while ((wi = __fgetwc_unlock(fp)) != WEOF && width != 0 && ((c == CT_CCL && in_ccl(wi, ccl)) || (c == CT_STRING && !iswspace(wi)))) {
if (width >= MB_CUR_MAX && !(flags & SUPPRESS)) {
nconv = wcrtomb(mbp, wi, &mbs);
- if (nconv == (size_t)-1) goto input_failure;
+ if (nconv == static_cast<size_t>(-1)) goto input_failure;
} else {
nconv = wcrtomb(mbbuf, wi, &mbs);
- if (nconv == (size_t)-1) goto input_failure;
+ if (nconv == static_cast<size_t>(-1)) goto input_failure;
if (nconv > width) break;
if (!(flags & SUPPRESS)) memcpy(mbp, mbbuf, nconv);
}
@@ -485,7 +486,7 @@
case 'e':
case 'f':
if (base == 0) base = 10;
- if (base != 16 && (int)(c - '0') >= base) break; /* not legal here */
+ if (base != 16 && static_cast<int>(c - '0') >= base) break; /* not legal here */
flags &= ~(SIGNOK | PFBOK | PFXOK | NDIGITS);
goto ok;
@@ -523,7 +524,7 @@
/*
* c is legal: store it and look at the next.
*/
- *p++ = (wchar_t)c;
+ *p++ = static_cast<wchar_t>(c);
}
/*
* If we had only a sign, it is no good; push back the sign.
@@ -548,7 +549,7 @@
else
res = wcstoumax(buf, NULL, base);
if (flags & POINTER)
- *va_arg(ap, void**) = (void*)(uintptr_t)res;
+ *va_arg(ap, void**) = reinterpret_cast<void*>(res);
else if (flags & MAXINT)
*va_arg(ap, intmax_t*) = res;
else if (flags & LLONG)
@@ -587,7 +588,7 @@
float res = wcstof(buf, &p);
*va_arg(ap, float*) = res;
}
- if (p - buf != (ptrdiff_t)width) abort();
+ if (static_cast<size_t>(p - buf) != width) abort();
nassigned++;
}
nread += width;