Re: _access function error
Didn't the compiler give you a warning about this string?
Hopefully you see that this string is not what you think it is, due to it having escape sequences.
The string really is this:
Code:
"C:<tab>emp<tab>est.ini"
So do you have a file that has a name with embedded tab characters? The obvious fix is to use "\\" and not "\" in string literals.
Regards,
Paul McKenzie
Re: _access function error
Sorry I forgot to put "\\" when posting this. My mistake on the post.
Suppose to be like this:
Code:
char INIFilename[256]="C:\\temp\\test.ini";
No, I do not have file with embedded tab characters.
Anyway, thanks for your info. Will try to find out why.
Re: _access function error
Quote:
Originally Posted by
PHChang
Sorry I forgot to put "\\" when posting this. My mistake on the post.
Instead of typing in the code, you should be copying and pasting the exact code you're running. Otherwise there could be other typos or missing code that affects the error that no one would know about.
Second, GetLastError() is not used to get further information if _access() returns an error value. Please see the documentation:
http://msdn.microsoft.com/en-us/library/1w06ktdy.aspx
Regards,
Paul McKenzie
Re: _access function error
Thanks for your advise. I will take note.
Perhaps I will try to add code below to find out more on the error:
_get_errno( &err );
printf( "errno = %d\n", err );
Code:
char INIFilename[256]="C:\\temp\\test.ini";
unsigned long Error = 0;
errno_t err;
if( _access( INIFilename, 00 ) != 0 )
{
_get_errno( &err );
printf( "errno = %d\n", err );
Error= GetLastError();
printf ("Failed to access INI file %s (%ul)", INIFilename, Error);
}
Re: _access function error
_access will also fail if you are lacking the necessary rights to the volume, share or directory.
typically speaking, if you can see the file in Windows Explorer, then _access(name, 0) will return 0, if you can't, then it will return error, even if the file is physically there.