From ff87813715ec32741ce230dd37c13d0ae6673f9c Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Tue, 7 Apr 2020 15:02:15 -0700 Subject: [PATCH] Don't expose unavailable cstdio functions. Summary: These aren't available on Android in all configurations. Reviewers: EricWF, mclow.lists, #libc, ldionne Reviewed By: EricWF, #libc, ldionne Subscribers: broadwaylamb, dexonsmith, ldionne, krytarowski, libcxx-commits Tags: #libc Differential Revision: https://reviews.llvm.org/D76093 --- libcxx/include/__config | 7 ++++++ libcxx/include/cstdio | 4 ++++ .../depr.c.headers/no_fgetpos_fsetpos.fail.cpp | 25 ++++++++++++++++++++++ .../test/std/depr/depr.c.headers/stdio_h.pass.cpp | 4 ++++ .../file.streams/c.files/cstdio.pass.cpp | 4 ++++ 5 files changed, 44 insertions(+) create mode 100644 libcxx/test/libcxx/depr/depr.c.headers/no_fgetpos_fsetpos.fail.cpp diff --git a/libcxx/include/__config b/libcxx/include/__config index ce7a935..ba565d2 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -1545,6 +1545,13 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( #define _LIBCPP_BUILTIN_CONSTANT_P(x) false #endif +// Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set +// of functions used in cstdio may not be available for low API levels when +// using 64-bit file offsets on LP32. +#if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24 +#define _LIBCPP_HAS_NO_FGETPOS_FSETPOS +#endif + #endif // __cplusplus #endif // _LIBCPP_CONFIG diff --git a/libcxx/include/cstdio b/libcxx/include/cstdio index 0f3f42d..d0492a0 100644 --- a/libcxx/include/cstdio +++ b/libcxx/include/cstdio @@ -131,9 +131,13 @@ using ::putc; using ::ungetc; using ::fread; using ::fwrite; +#ifndef _LIBCPP_HAS_NO_FGETPOS_FSETPOS using ::fgetpos; +#endif using ::fseek; +#ifndef _LIBCPP_HAS_NO_FGETPOS_FSETPOS using ::fsetpos; +#endif using ::ftell; using ::rewind; using ::clearerr; diff --git a/libcxx/test/libcxx/depr/depr.c.headers/no_fgetpos_fsetpos.fail.cpp b/libcxx/test/libcxx/depr/depr.c.headers/no_fgetpos_fsetpos.fail.cpp new file mode 100644 index 0000000..7c28be0 --- /dev/null +++ b/libcxx/test/libcxx/depr/depr.c.headers/no_fgetpos_fsetpos.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: verify-support + +#include + +using T = decltype(::fgetpos); +#ifdef _LIBCPP_HAS_NO_FGETPOS_FSETPOS +// expected-error@-2 {{no such thing}} +#else +// expected-no-diagnostics +#endif + +using U = decltype(::fsetpos); +#ifdef _LIBCPP_HAS_NO_FGETPOS_FSETPOS +// expected-error@-2 {{no such thing}} +#else +// expected-no-diagnostics +#endif diff --git a/libcxx/test/std/depr/depr.c.headers/stdio_h.pass.cpp b/libcxx/test/std/depr/depr.c.headers/stdio_h.pass.cpp index 97ea0d4..43a0e29 100644 --- a/libcxx/test/std/depr/depr.c.headers/stdio_h.pass.cpp +++ b/libcxx/test/std/depr/depr.c.headers/stdio_h.pass.cpp @@ -156,9 +156,13 @@ int main(int, char**) static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); +#ifndef _LIBCPP_HAS_NO_FGETPOS_FSETPOS static_assert((std::is_same::value), ""); +#endif static_assert((std::is_same::value), ""); +#ifndef _LIBCPP_HAS_NO_FGETPOS_FSETPOS static_assert((std::is_same::value), ""); +#endif static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); diff --git a/libcxx/test/std/input.output/file.streams/c.files/cstdio.pass.cpp b/libcxx/test/std/input.output/file.streams/c.files/cstdio.pass.cpp index af8dc97..bae82fe 100644 --- a/libcxx/test/std/input.output/file.streams/c.files/cstdio.pass.cpp +++ b/libcxx/test/std/input.output/file.streams/c.files/cstdio.pass.cpp @@ -120,9 +120,13 @@ int main(int, char**) static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); +#ifndef _LIBCPP_HAS_NO_FGETPOS_FSETPOS static_assert((std::is_same::value), ""); +#endif static_assert((std::is_same::value), ""); +#ifndef _LIBCPP_HAS_NO_FGETPOS_FSETPOS static_assert((std::is_same::value), ""); +#endif static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); static_assert((std::is_same::value), ""); -- 2.7.4