Windows: fix uv_fs_ftruncate to compile with Mingw32

Close: #382, #397
Ref: #381
This commit is contained in:
Keno Fischer 2012-04-29 02:29:55 +02:00 committed by Bert Belder
parent b386c44e5e
commit d13b1e0803
2 changed files with 23 additions and 3 deletions

View File

@ -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 File

@ -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