From 8aa4246ddef30c0e114362b6ef2a8e6ee0ed3817 Mon Sep 17 00:00:00 2001
From: Nikias Bassen
Date: Sat, 2 Feb 2019 03:15:25 +0100
Subject: win32: Use _lseeki64 instead of _fseeki64/_ftelli64 and don't link
 against msvcr100.dll

What a mess it is, all these msvcr*.dll - incompatible without limits
---
 configure.ac   |  2 +-
 src/asr.c      | 12 +++++-------
 src/download.c |  2 +-
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/configure.ac b/configure.ac
index c67c0ac..6191c89 100644
--- a/configure.ac
+++ b/configure.ac
@@ -53,7 +53,7 @@ case "$host_os" in
 	;;
 	mingw*)
 		GLOBAL_CFLAGS+="-DWIN32 -D__LITTLE_ENDIAN__=1"
-		AC_LDFLAGS+="-static-libgcc -lmsvcr100"
+		AC_LDFLAGS+="-static-libgcc"
 	;;
 	*)
 	;;
diff --git a/src/asr.c b/src/asr.c
index 9fcb6b3..3800c2b 100644
--- a/src/asr.c
+++ b/src/asr.c
@@ -205,9 +205,8 @@ int asr_perform_validation(asr_client_t asr, const char* filesystem) {
 	}
 
 #ifdef WIN32
-	_fseeki64(file, 0, SEEK_END);
-	length = _ftelli64(file);
-	_fseeki64(file, 0, SEEK_SET);
+	length = _lseeki64(fileno(file), 0, SEEK_END);
+	_lseeki64(fileno(file), 0, SEEK_SET);
 #else
 	fseeko(file, 0, SEEK_END);
 	length = ftello(file);
@@ -307,7 +306,7 @@ int asr_handle_oob_data_request(asr_client_t asr, plist_t packet, FILE* file) {
 	}
 
 #ifdef WIN32
-	_fseeki64(file, oob_offset, SEEK_SET);
+	_lseeki64(fileno(file), oob_offset, SEEK_SET);
 #else
 	fseeko(file, oob_offset, SEEK_SET);
 #endif
@@ -341,9 +340,8 @@ int asr_send_payload(asr_client_t asr, const char* filesystem) {
 	}
 
 #ifdef WIN32
-	_fseeki64(file, 0, SEEK_END);
-	length = _ftelli64(file);
-	_fseeki64(file, 0, SEEK_SET);
+	length = _lseeki64(fileno(file), 0, SEEK_END);
+	_lseeki64(fileno(file), 0, SEEK_SET);
 #else
 	fseeko(file, 0, SEEK_END);
 	length = ftello(file);
diff --git a/src/download.c b/src/download.c
index 8bae52f..e09d911 100644
--- a/src/download.c
+++ b/src/download.c
@@ -140,7 +140,7 @@ int download_to_file(const char* url, const char* filename, int enable_progress)
 	curl_easy_cleanup(handle);
 
 #ifdef WIN32
-	uint64_t sz = _ftelli64(f);
+	uint64_t sz = _lseeki64(fileno(f), 0, SEEK_CUR);
 #else
 	off_t sz = ftello(f);
 #endif
-- 
cgit v1.1-32-gdbae