diff --git a/libcxx/test/support/filesystem_test_helper.h b/libcxx/test/support/filesystem_test_helper.h --- a/libcxx/test/support/filesystem_test_helper.h +++ b/libcxx/test/support/filesystem_test_helper.h @@ -99,6 +99,27 @@ } #endif +#if defined(__LP64__) || defined(_WIN32) || defined(__MVS__) + // N.B. libc might define some of these identifiers using macros from + // foo64 -> foo or vice versa. + using off64_t = ::off_t; + inline FILE* fopen64(const char* pathname, const char* mode) { + return ::fopen(pathname, mode); + } + inline int ftruncate64(int fd, off64_t length) { + return ::ftruncate(fd, length); + } +#elif defined(__BIONIC__) + // Bionic does not distinguish between fopen and fopen64, and it has an + // ftruncate64 that accepts off64_t. + using ::off64_t, ::ftruncate64; + inline FILE* fopen64(const char* pathname, const char* mode) { + return ::fopen(pathname, mode); + } +#else + using ::off64_t, ::fopen64, ::ftruncate64; +#endif + inline std::string getcwd() { // Assume that path lengths are not greater than this. // This should be fine for testing purposes. @@ -185,22 +206,11 @@ // off_t). On a 32-bit system this allows us to create a file larger than // 2GB. std::string create_file(fs::path filename_path, uintmax_t size = 0) { - std::string filename = filename_path.string(); -#if defined(__LP64__) || defined(_WIN32) || defined(__MVS__) - auto large_file_fopen = fopen; - auto large_file_ftruncate = utils::ftruncate; - using large_file_offset_t = off_t; -#else - auto large_file_fopen = fopen64; - auto large_file_ftruncate = ftruncate64; - using large_file_offset_t = off64_t; -#endif - - filename = sanitize_path(std::move(filename)); + std::string filename = sanitize_path(filename_path.string()); if (size > - static_cast::type>( - std::numeric_limits::max())) { + static_cast::type>( + std::numeric_limits::max())) { fprintf(stderr, "create_file(%s, %ju) too large\n", filename.c_str(), size); abort(); @@ -211,15 +221,15 @@ #else # define FOPEN_CLOEXEC_FLAG "e" #endif - FILE* file = large_file_fopen(filename.c_str(), "w" FOPEN_CLOEXEC_FLAG); + FILE* file = utils::fopen64(filename.c_str(), "w" FOPEN_CLOEXEC_FLAG); if (file == nullptr) { fprintf(stderr, "fopen %s failed: %s\n", filename.c_str(), strerror(errno)); abort(); } - if (large_file_ftruncate( - fileno(file), static_cast(size)) == -1) { + if (utils::ftruncate64( + fileno(file), static_cast(size)) == -1) { fprintf(stderr, "ftruncate %s %ju failed: %s\n", filename.c_str(), size, strerror(errno)); fclose(file);