-
September 21st, 2013, 12:20 PM
#1
_access function error
Just wonder is it possible that if the file exist, this function below will fail by returning non-zero value?
_access( INIFilename, 00 )
00 - check for Existence only
I noticed that sometimes if even the file exist, the function will fail or return non-zero value.
So trying to find out and duplicate this error. It tends to happen intermittently.
Any idea how can I find out what causing this error?
Code:
char INIFilename[256]="C:\temp\test.ini";
unsigned long Error = 0;
if( _access( INIFilename, 00 ) != 0 )
{
Error= GetLastError();
printf ("Failed to access INI file %s (%ul)", INIFilename, Error);
}
-
September 21st, 2013, 12:28 PM
#2
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
Last edited by Paul McKenzie; September 21st, 2013 at 12:36 PM.
-
September 21st, 2013, 09:04 PM
#3
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.
-
September 21st, 2013, 09:14 PM
#4
Re: _access function error
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
-
September 22nd, 2013, 05:24 AM
#5
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);
}
-
September 24th, 2013, 03:42 AM
#6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|