[PATCH 14/17] Add ftruncate implementation for MSVC
- From
Marius Storm-Olsen <mstormo@gmail.com>
- Date
- Sep 14, 2009, 13:11 UTC
- Message-ID
- <c95a367520435feec0833d2d0edc33d86cf939a8.1252925290.git.mstormo@gmail.com>
- In-Reply-To
- <9c5670f92cd0b3b8b74dd2204698e9c45ad03c90.1252925290.git.mstormo@gmail.com>
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@gmail.com> --- 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