From ca242f2c366a02d108ae846637614800c1932fca Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Fri, 3 Dec 2010 18:48:56 +0000 Subject: [PATCH] Support/FileSystem: Fix MinGW build. It doesn't have _chsize_s. llvm-svn: 120826 --- llvm/cmake/config-ix.cmake | 3 +++ llvm/include/llvm/Config/config.h.cmake | 3 +++ llvm/lib/Support/Windows/PathV2.inc | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake index 3fd0c4567508..27f2964038ba 100755 --- a/llvm/cmake/config-ix.cmake +++ b/llvm/cmake/config-ix.cmake @@ -108,6 +108,9 @@ check_symbol_exists(strerror string.h HAVE_STRERROR) check_symbol_exists(strerror_r string.h HAVE_STRERROR_R) check_symbol_exists(strerror_s string.h HAVE_STRERROR_S) check_symbol_exists(setenv stdlib.h HAVE_SETENV) +if ( LLVM_ON_WIN32 ) + check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S) +endif() check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC) if( LLVM_USING_GLIBC ) diff --git a/llvm/include/llvm/Config/config.h.cmake b/llvm/include/llvm/Config/config.h.cmake index 26a39b224e49..4ebae94944ec 100644 --- a/llvm/include/llvm/Config/config.h.cmake +++ b/llvm/include/llvm/Config/config.h.cmake @@ -327,6 +327,9 @@ /* Define to 1 if you have the `setenv' function. */ #cmakedefine HAVE_SETENV ${HAVE_SETENV} +/* Define to 1 if you have the `_chsize_s' function. */ +#cmakedefine HAVE__CHSIZE_S ${HAVE__CHSIZE_S} + /* Define to 1 if you have the `setjmp' function. */ #undef HAVE_SETJMP diff --git a/llvm/lib/Support/Windows/PathV2.inc b/llvm/lib/Support/Windows/PathV2.inc index da5e8b60bd00..8377310388c9 100644 --- a/llvm/lib/Support/Windows/PathV2.inc +++ b/llvm/lib/Support/Windows/PathV2.inc @@ -310,7 +310,11 @@ error_code resize_file(const Twine &path, uint64_t size) { int fd = ::_wopen(path_utf16.begin(), O_BINARY, S_IREAD | S_IWRITE); if (fd == -1) return error_code(errno, generic_category()); +#ifdef HAVE__CHSIZE_S errno_t error = ::_chsize_s(fd, size); +#else + errno_t error = ::_chsize(fd, size); +#endif ::close(fd); return error_code(error, generic_category()); }