Permalink
Browse files

Attempt to fix #382

  • Loading branch information...
1 parent e2cae34 commit 9cec5f1874de78286104e21442d9a186b017a181 @Keno Keno committed Apr 28, 2012
Showing with 21 additions and 2 deletions.
  1. +17 −2 src/win/fs.c
  2. +4 −0 src/win/winapi.h
View
@@ -574,10 +574,25 @@ void fs__fsync(uv_fs_t* req, uv_file file) {
void fs__ftruncate(uv_fs_t* req, uv_file file, int64_t offset) {
int result;
-
+ HANDLE handle;
+ NTSTATUS nt_status;
+ IO_STATUS_BLOCK io_status;
+ FILE_END_OF_FILE_INFORMATION eof_info;
+
VERIFY_UV_FILE(file, req);
- result = _chsize_s(file, offset);
+ handle = (HANDLE)_get_osfhandle(file);
+
+ eof_info.EndOfFile.QuadPart = offset;
+
+ nt_status = pNtSetInformationFile(handle,
+ &io_status,
+ &eof_info,
+ sizeof eof_info,
+ FileEndOfFileInformation);
+
+ result = (nt_status==STATUS_SUCCESS)-1;
+
SET_REQ_RESULT(req, result);
}
View
@@ -4141,6 +4141,10 @@ typedef struct _FILE_MODE_INFORMATION {
ULONG Mode;
} FILE_MODE_INFORMATION, *PFILE_MODE_INFORMATION;
+typedef struct _FILE_END_OF_FILE_INFORMATION {
+ LARGE_INTEGER EndOfFile;
+} FILE_END_OF_FILE_INFORMATION, *PFILE_END_OF_FILE_INFORMATION;
+
#define FILE_SYNCHRONOUS_IO_ALERT 0x00000010
#define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020

0 comments on commit 9cec5f1

Please sign in to comment.