joyent/libuv — Issue #309: Provide binding to truncate as well as ftruncate
Author: isaacs
Created: 2012-02-07 23:09:51+00:00
State: open

On windows, do open/_chsize/close. The unix version should be something like this:

```patch
diff --git a/include/uv.h b/include/uv.h
index f0f1ff3..c301fcd 100644
--- a/include/uv.h
+++ b/include/uv.h
@@ -1188,6 +1188,7 @@ typedef enum {
UV_FS_STAT,
UV_FS_LSTAT,
UV_FS_FSTAT,
+ UV_FS_TRUNCATE,
UV_FS_FTRUNCATE,
UV_FS_UTIME,
UV_FS_FUTIME,
@@ -1261,6 +1262,9 @@ UV_EXTERN int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file,
UV_EXTERN int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file,
uv_fs_cb cb);

+UV_EXTERN int uv_fs_truncate(uv_loop_t* loop, uv_fs_t* req, const char* path,
+ off_t offset, uv_fs_cb cb);
+
UV_EXTERN int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file file,
off_t offset, uv_fs_cb cb);

diff --git a/src/unix/fs.c b/src/unix/fs.c
index 6615516..937e393 100644
--- a/src/unix/fs.c
+++ b/src/unix/fs.c
@@ -461,6 +461,12 @@ int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
}

+int uv_fs_truncate(uv_loop_t* loop, uv_fs_t* req, const char* path,
+ off_t offset, uv_fs_cb cb) {
+ WRAP_EIO(UV_FS_TRUNCATE, eio_truncate, truncate, ARGS2(file, offset))
+}
+
+
int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file file, off_t offset,
uv_fs_cb cb) {
char* path = NULL;
```