Allow a file to be shared when opened read only. Return success when reading past the end of file.

git-svn-id: http://yate.null.ro/svn/yate/trunk@2541 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2009-03-25 17:35:08 +00:00
parent 14fea4a0d1
commit a5c7c43846
1 changed files with 8 additions and 1 deletions

View File

@ -644,7 +644,10 @@ bool File::openPath(const char* name, bool canWrite, bool canRead,
createMode = (!canRead && !append) ? CREATE_ALWAYS : OPEN_ALWAYS;
else
createMode = OPEN_EXISTING;
HANDLE h = CreateFile(name,access,0,NULL,createMode,FILE_ATTRIBUTE_NORMAL,NULL);
DWORD share = 0;
if (!canWrite && canRead)
share |= FILE_SHARE_READ;
HANDLE h = CreateFile(name,access,share,NULL,createMode,FILE_ATTRIBUTE_NORMAL,NULL);
if (h == invalidHandle()) {
copyError();
return false;
@ -766,6 +769,10 @@ int File::readData(void* buffer, int length)
clearError();
return nbytes;
}
else if (::GetLastError() == ERROR_HANDLE_EOF) {
clearError();
return 0;
}
copyError();
return -1;
#else