Thread (32 messages) flat view 32 messages, 7 authors, 2016-06-15
DORMANTno replies

[PATCH 14/17] Add ftruncate implementation for MSVC

From: Marius Storm-Olsen <hidden>
Date: 2016-06-15 22:47:24
Subsystem: the rest · Maintainer: Linus Torvalds

The MSVC Posix implementation doesn't contain ftruncate, so add our own
which can handle large files (64bit offsets).

Signed-off-by: Marius Storm-Olsen <redacted>
---
 compat/msvc.c |    8 ++++++++
 compat/msvc.h |    2 ++
 2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/compat/msvc.c b/compat/msvc.c
index ac04a4c..b96b045 100644
--- a/compat/msvc.c
+++ b/compat/msvc.c
@@ -32,4 +32,12 @@ int closedir(DIR *dir)
 	return 0;
 }
 
+int ftruncate(int fd, __int64 length)
+{
+	HANDLE fh = (HANDLE)_get_osfhandle(fd);
+	if (!fh || _lseeki64(fd, length, SEEK_SET))
+		return -1;
+	return SetEndOfFile(fh) ? 0 : -1;
+}
+
 #include "mingw.c"
diff --git a/compat/msvc.h b/compat/msvc.h
index a62507f..d9fc04b 100644
--- a/compat/msvc.h
+++ b/compat/msvc.h
@@ -46,4 +46,6 @@ struct _stati64 {
 	time_t  st_mtime;
 	time_t  st_ctime;
 };
+
+int ftruncate(int fd, __int64 length);
 #endif
-- 
1.6.2.1.418.g33d56.dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help