Reputation: 5837
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?
Upvotes: 7
Views: 233
Reputation: 104698
It's likely UTF-8. To be safe, you should use CFURLGetFileSystemRepresentation
for URLs and -[NSString fileSystemRepresentation]
for paths.
Upvotes: 3
Reputation: 89509
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.
Upvotes: 2