Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Windows: fix uv_fs_ftruncate to compile with Mingw32
Browse files Browse the repository at this point in the history
Close: #382, #397
Ref: #381
  • Loading branch information
Keno authored and piscisaureus committed Apr 29, 2012
1 parent b386c44 commit d13b1e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/win/fs.c
Expand Up @@ -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));
}
}


Expand Down
4 changes: 4 additions & 0 deletions src/win/winapi.h
Expand Up @@ -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

Expand Down

0 comments on commit d13b1e0

Please sign in to comment.