I had a little bug today that caused me to scratch my head for a bit. It turned out that if you use NSBundle followed by NSString UTF8String to get a path for a resource in your app bundle and convert it to a char * and then call fopen in a dynamic library you are linking too it results in EXEC_BAD_ACCESS but calling fopen locally is fine.
I've fixed the problem but I'd like some ideas why this causes errors. I ran the debugger and it said that it had crashed on a call to flockfile in fopen which is documented here: http://www.opengroup.org/onlinepubs/000095399/functions/flockfile.html which seems to suggest a locking issue. But then that is even harder to understand than what I assume to be a permissions error of some sort.
Unless code from a dynamic library runs in a separate process and thus locks files it has opened so passing a FILE * back results is nasty things happening.
Any ideas?
Edit: Ah, on closer inspection it seems that it is closer to the last point. Strange, I had never heard that was a problem before. I guess I should have worked it out though. Oh well.
I've fixed the problem but I'd like some ideas why this causes errors. I ran the debugger and it said that it had crashed on a call to flockfile in fopen which is documented here: http://www.opengroup.org/onlinepubs/000095399/functions/flockfile.html which seems to suggest a locking issue. But then that is even harder to understand than what I assume to be a permissions error of some sort.
Unless code from a dynamic library runs in a separate process and thus locks files it has opened so passing a FILE * back results is nasty things happening.
Any ideas?
Edit: Ah, on closer inspection it seems that it is closer to the last point. Strange, I had never heard that was a problem before. I guess I should have worked it out though. Oh well.