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?
It's likely UTF-8. To be safe, you should use CFURLGetFileSystemRepresentation
for URLs and -[NSString fileSystemRepresentation]
for paths.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With