Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What type should I use for filename strings in C for iOS project?

I have a C library that I'm using from within an iOS Objective-C program. One of the functions of my C library reads in and processes data from a file. Currently that function looks something like this

internalType* parseFile(const char* filename);

Is passing in a char* for the filename like this safe on iOS or am I shooting myself in the foot with unicode? Is there a preferred practice here?

like image 637
wxs Avatar asked Jan 05 '12 22:01

wxs


2 Answers

It's likely UTF-8. To be safe, you should use CFURLGetFileSystemRepresentation for URLs and -[NSString fileSystemRepresentation] for paths.

like image 101
justin Avatar answered Nov 15 '22 15:11

justin


Yes... const char * should work fine for C things, especially as they match the C functions you're likely to call into, such as fopen.

If your files are likely to have wacky non-Ascii filenames though, all bets are off. :-) You would be safer doing the Objective C calls which take NSURL's or NSString objects.

like image 2
Michael Dautermann Avatar answered Nov 15 '22 16:11

Michael Dautermann