Skip to content
Browse files

Windows: fix uv_fs_ftruncate to compile with Mingw32

Close: #382, #397
Ref: #381
  • Loading branch information...
1 parent b386c44 commit d13b1e0803b7903373aaba8aa76406ee94f43a7d @Keno Keno committed with piscisaureus
Showing with 23 additions and 3 deletions.
  1. +19 −3 src/win/fs.c
  2. +4 −0 src/win/winapi.h
View
22 src/win/fs.c
@@ -573,12 +573,28 @@ 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 status;
+ IO_STATUS_BLOCK io_status;
+ FILE_END_OF_FILE_INFORMATION eof_info;
VERIFY_UV_FILE(file, req);
- result = _chsize_s(file, offset);
- SET_REQ_RESULT(req, result);
+ handle = (HANDLE)_get_osfhandle(file);
+
+ eof_info.EndOfFile.QuadPart = offset;
+
+ status = pNtSetInformationFile(handle,
+ &io_status,
+ &eof_info,
+ sizeof eof_info,
+ FileEndOfFileInformation);
+
+ if (NT_SUCCESS(status)) {
+ SET_REQ_RESULT(req, 0);
+ } else {
+ SET_REQ_WIN32_ERROR(req, pRtlNtStatusToDosError(status));
+ }
}
View
4 src/win/winapi.h
@@ -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 d13b1e0

Please sign in to comment.
Something went wrong with that request. Please try again.