From 5f639c995ef10fd46c5638be3f730634c073cc26 Mon Sep 17 00:00:00 2001 From: jaakkor2 Date: Wed, 15 Nov 2017 17:23:30 +0100 Subject: [PATCH 1/2] Use _chsize_s on Windows for truncate Proposal to fix https://github.com/JuliaLang/julia/issues/24466 . Should allow files >2 GB to be truncated on Windows. --- src/support/ios.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/support/ios.c b/src/support/ios.c index 360e29e603968..65280fcafea60 100644 --- a/src/support/ios.c +++ b/src/support/ios.c @@ -566,7 +566,11 @@ int ios_trunc(ios_t *s, size_t size) #if !defined(_OS_WINDOWS_) if (ftruncate(s->fd, size) == 0) #else - if (_chsize(s->fd, size) == 0) + #if !defined(__MINGW32__) || defined(MINGW_HAS_SECURE_API) + if (_chsize_s(s->fd, size) == 0) + #else + if (_chsize(s->fd, size) == 0) + #endif #endif return 0; } From ff66841c738677657d4ce142549ae067949c37ba Mon Sep 17 00:00:00 2001 From: jaakkor2 Date: Wed, 15 Nov 2017 17:54:08 +0100 Subject: [PATCH 2/2] Update ios.c Checking Windows 32bit build https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6.1-win32.exe , libgit2.dll does use `_chsize_c`, so both 32bit and 64bit should be able to use `_chsize_c`. --- src/support/ios.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/support/ios.c b/src/support/ios.c index 65280fcafea60..f8619ea834051 100644 --- a/src/support/ios.c +++ b/src/support/ios.c @@ -566,11 +566,7 @@ int ios_trunc(ios_t *s, size_t size) #if !defined(_OS_WINDOWS_) if (ftruncate(s->fd, size) == 0) #else - #if !defined(__MINGW32__) || defined(MINGW_HAS_SECURE_API) - if (_chsize_s(s->fd, size) == 0) - #else - if (_chsize(s->fd, size) == 0) - #endif + if (_chsize_s(s->fd, size) == 0) #endif return 0; }