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
This commit is contained in:
Dan Albert 2020-04-07 15:02:15 -07:00
parent 82576d6fec
commit ff87813715
5 changed files with 44 additions and 0 deletions

View File

@ -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

View File

@ -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;

View File

@ -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 <cstdio>
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

View File

@ -156,9 +156,13 @@ int main(int, char**)
static_assert((std::is_same<decltype(ungetc(0,fp)), int>::value), "");
static_assert((std::is_same<decltype(fread((void*)0,0,0,fp)), size_t>::value), "");
static_assert((std::is_same<decltype(fwrite((const void*)arr,1,0,fp)), size_t>::value), "");
#ifndef _LIBCPP_HAS_NO_FGETPOS_FSETPOS
static_assert((std::is_same<decltype(fgetpos(fp, &fpos)), int>::value), "");
#endif
static_assert((std::is_same<decltype(fseek(fp, 0,0)), int>::value), "");
#ifndef _LIBCPP_HAS_NO_FGETPOS_FSETPOS
static_assert((std::is_same<decltype(fsetpos(fp, &fpos)), int>::value), "");
#endif
static_assert((std::is_same<decltype(ftell(fp)), long>::value), "");
static_assert((std::is_same<decltype(rewind(fp)), void>::value), "");
static_assert((std::is_same<decltype(clearerr(fp)), void>::value), "");

View File

@ -120,9 +120,13 @@ int main(int, char**)
static_assert((std::is_same<decltype(std::ungetc(0,fp)), int>::value), "");
static_assert((std::is_same<decltype(std::fread((void*)0,0,0,fp)), std::size_t>::value), "");
static_assert((std::is_same<decltype(std::fwrite((const void*)0,0,0,fp)), std::size_t>::value), "");
#ifndef _LIBCPP_HAS_NO_FGETPOS_FSETPOS
static_assert((std::is_same<decltype(std::fgetpos(fp, &fpos)), int>::value), "");
#endif
static_assert((std::is_same<decltype(std::fseek(fp, 0,0)), int>::value), "");
#ifndef _LIBCPP_HAS_NO_FGETPOS_FSETPOS
static_assert((std::is_same<decltype(std::fsetpos(fp, &fpos)), int>::value), "");
#endif
static_assert((std::is_same<decltype(std::ftell(fp)), long>::value), "");
static_assert((std::is_same<decltype(std::rewind(fp)), void>::value), "");
static_assert((std::is_same<decltype(std::clearerr(fp)), void>::value), "");