Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Talk:Checking if a file exists in Open C and C++

From Wiki
Jump to: navigation, search

PankajChoudhary -

Hi

I have found bug in the function OpenCFileExists() and OpenCppFileExists().

bool OpenCFileExists(const char* filename)
{
FILE* fp = NULL;
 
//this will fail if more capabilities to read the
//contents of the file is required (e.g. \private\...)
fp = fopen(filename, "r");
 
if(fp != NULL)
{
fclose(fp);
return true;
}
fclose(fp); /* BUG -- This fclose() function will call when fp=NULL only. Hence, It will crash with Segmentation fault. */
 
return false;
}

Same mistake in OpenCppFileExists() function also.

- Pankaj Choudhary

PankajChoudhary (talk) 12:25, 29 October 2013 (EET)

Hamishwillee - Pankaj - its a wiki

Hi Pankaj

Generally this is a wiki, so if you're sure that the code is incorrect you can edit it yourself!

So you're saying that the second call of fclose will cause a fault - I would have thought calling fclose on "nothing" wouldn't do anything. If you're right then removing this line should fix the problem right?

Regards

H

hamishwillee (talk) 06:46, 5 November 2013 (EET)

 

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×