From 3c5fa553bbe248ff497571b4a029dbc3fcbdcc6c Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 26 Feb 2008 20:05:36 +0100 Subject: [PATCH] POSIX compatible ftruncate() for Windows --- src/lib/w32/posixio.c | 9 +++++++++ src/lib/w32/unistd.h | 1 + 2 files changed, 10 insertions(+) diff --git a/src/lib/w32/posixio.c b/src/lib/w32/posixio.c index eb4c57c3..31be7c2d 100644 --- a/src/lib/w32/posixio.c +++ b/src/lib/w32/posixio.c @@ -412,6 +412,15 @@ posix_fsync(int fd) FILE_FUNCTION(FDMAP_IO_FILE, _commit(handle)) } +/* + * POSIX ftruncate() + */ +int +ftruncate(int fd, off_t length) +{ + FILE_FUNCTION(FDMAP_IO_FILE, _chsize(handle, length)) +} + /* * POSIX equivalent for fstat(). * fstat() is used instead of _fstat(), diff --git a/src/lib/w32/unistd.h b/src/lib/w32/unistd.h index f382f70a..807be4a5 100644 --- a/src/lib/w32/unistd.h +++ b/src/lib/w32/unistd.h @@ -127,6 +127,7 @@ extern int fcntl(int fd, int cmd, ...); posix_write((fd), (buffer), (count)) #define fsync(fd) \ posix_fsync((fd)) +extern int ftruncate(int fd, off_t length); extern int posix_close(int fd); extern off_t posix_lseek(int fd, off_t offset, int origin); extern ssize_t posix_read(int fd, void *buffer, size_t count);