Re: _access
In message <822AAA1C-C7B5-4D9F-A36B-0E49054C84D8@microsoft.com>, Tim
<Tim@discussions.microsoft.com> writes
I2"m using _access(2ZFile.txt2\,2) to see if I have permission to write to
a file.
It works most of the time but when the file is on a network, and the network
permission for the specified user has the write permission is denied it fails.
Can anyone tell me how do I tell determine this to be true?
Thank you,
Tim
There was a thread, maybe in comp.os.ms-windows.programmer.win32, last
year about _access being broken except to confirm a file's existence. I
have a vague recollection that a Microsoft person confirmed this and
offered a non-intrusive workaround:
int CheckAccessMode(LPCTSTR pszFilename, int nMode)
{
if (0 == nMode)
// _access() does fine when checking for existence only
return(_access(pszFilename, nMode));
DWORD dwAccessMode;
if (2 == nMode) dwAccessMode = GENERIC_WRITE;
else if (4 == nMode) dwAccessMode = GENERIC_READ;
else if (6 == nMode) dwAccessMode = GENERIC_READ | GENERIC_WRITE;
else
{
assert(0);
return(-1);
}
HANDLE hFile = CreateFile(pszFilename,
dwAccessMode,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_BACKUP_SEMANTICS,
NULL);
if (INVALID_HANDLE_VALUE == hFile)
return(-1);
if (!CloseHandle(hFile))
assert(0);
return(0);
}
--
Fenster