8204310: Simpler RandomAccessFile.setLength() on Windows

Reviewed-by: alanb
This commit is contained in:
Ivan Gerasimov 2018-06-29 17:35:04 -07:00
parent bebd49cf84
commit 8774d70044
4 changed files with 289 additions and 50 deletions

View file

@ -458,19 +458,20 @@ handleSync(FD fd) {
return 0;
}
int
jint
handleSetLength(FD fd, jlong length) {
HANDLE h = (HANDLE)fd;
long high = (long)(length >> 32);
DWORD ret;
FILE_END_OF_FILE_INFO eofInfo;
if (h == (HANDLE)(-1)) return -1;
ret = SetFilePointer(h, (long)(length), &high, FILE_BEGIN);
if (ret == 0xFFFFFFFF && GetLastError() != NO_ERROR) {
eofInfo.EndOfFile.QuadPart = length;
if (h == INVALID_HANDLE_VALUE) {
return -1;
}
if (!SetFileInformationByHandle(h, FileEndOfFileInfo, &eofInfo,
sizeof(FILE_END_OF_FILE_INFO))) {
return -1;
}
if (SetEndOfFile(h) == FALSE) return -1;
return 0;
}

View file

@ -43,7 +43,7 @@ WCHAR* currentDir(int di);
int currentDirLength(const WCHAR* path, int pathlen);
int handleAvailable(FD fd, jlong *pbytes);
int handleSync(FD fd);
int handleSetLength(FD fd, jlong length);
jint handleSetLength(FD fd, jlong length);
jlong handleGetLength(FD fd);
JNIEXPORT jint handleRead(FD fd, void *buf, jint len);
jint handleWrite(FD fd, const void *buf, jint len);