[PATCH 14/17] Add ftruncate implementation for MSVC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <mstormo@xxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]