From 4b3d007c4d40ccf7c364e18aafb7b9676c22662b Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 9 Dec 2016 05:20:43 +0000 Subject: [PATCH] Re-commit r289184, "Support: Use a 64-bit seek in raw_fd_ostream::seek()." with a configure-time check for lseek64. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289187 91177308-0d34-0410-b5e6-96231b3b80d8 --- cmake/config-ix.cmake | 3 +++ include/llvm/Config/config.h.cmake | 3 +++ lib/Support/raw_ostream.cpp | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake index 7ce2eb0adf0..71c1af5bd27 100755 --- a/cmake/config-ix.cmake +++ b/cmake/config-ix.cmake @@ -173,6 +173,9 @@ endif() if( HAVE_SYS_UIO_H ) check_symbol_exists(writev sys/uio.h HAVE_WRITEV) endif() +set(CMAKE_REQUIRED_DEFINITIONS "-D_LARGEFILE64_SOURCE") +check_symbol_exists(lseek64 "sys/types.h;unistd.h" HAVE_LSEEK64) +set(CMAKE_REQUIRED_DEFINITIONS "") check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL) check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO) check_symbol_exists(malloc_zone_statistics malloc/malloc.h diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake index 1331c4f4cbd..fe87829c2c2 100644 --- a/include/llvm/Config/config.h.cmake +++ b/include/llvm/Config/config.h.cmake @@ -120,6 +120,9 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_LINK_H ${HAVE_LINK_H} +/* Define to 1 if you have the `lseek64' function. */ +#cmakedefine HAVE_LSEEK64 ${HAVE_LSEEK64} + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_MACH_MACH_H ${HAVE_MACH_MACH_H} diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp index 92c7967cd8f..d073802db93 100644 --- a/lib/Support/raw_ostream.cpp +++ b/lib/Support/raw_ostream.cpp @@ -598,7 +598,13 @@ void raw_fd_ostream::close() { uint64_t raw_fd_ostream::seek(uint64_t off) { assert(SupportsSeeking && "Stream does not support seeking!"); flush(); +#ifdef LLVM_ON_WIN32 + pos = ::_lseeki64(FD, off, SEEK_SET); +#elif defined(HAVE_LSEEK64) + pos = ::lseek64(FD, off, SEEK_SET); +#else pos = ::lseek(FD, off, SEEK_SET); +#endif if (pos == (uint64_t)-1) error_detected(); return pos; -- 2.50.1