mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 23:34:52 +02:00
8204310: Simpler RandomAccessFile.setLength() on Windows
Reviewed-by: alanb
This commit is contained in:
parent
bebd49cf84
commit
8774d70044
4 changed files with 289 additions and 50 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue