Support/FileSystem: Fix MinGW build. It doesn't have _chsize_s.
authorMichael J. Spencer <bigcheesegs@gmail.com>
Fri, 3 Dec 2010 18:48:56 +0000 (18:48 +0000)
committerMichael J. Spencer <bigcheesegs@gmail.com>
Fri, 3 Dec 2010 18:48:56 +0000 (18:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120826 91177308-0d34-0410-b5e6-96231b3b80d8

cmake/config-ix.cmake
include/llvm/Config/config.h.cmake
lib/Support/Windows/PathV2.inc

index 3fd0c456750850dc8a8669d10a07e446f916fa75..27f2964038ba4084264a2017b4cc08a71e4a9913 100755 (executable)
@@ -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 )
index 26a39b224e490a7815ef63f12d8be3e577ab4afd..4ebae94944ecc0df6235b10b3b249ce32ac06bfb 100644 (file)
 /* 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
 
index da5e8b60bd00fc971c25c38bc9878c6c9825984b..8377310388c9864396b594d8587ef13e777221d5 100644 (file)
@@ -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());
 }