Can you use the C open(const char* name, int flag) function on the iPhone? Can you use the C open(const char* name, int flag) function on the iPhone? unix unix

Can you use the C open(const char* name, int flag) function on the iPhone?


You can use it, but the fcntl.h header is not included in the Foundation or UIKit frameworks by default. To use the open(2) system call, simply import that header wherever you use it (or add it to your pre-compiled header file).

For example:

#import <fcntl.h>// now you can use open or import your library header files


Why not? The only problem that it might have is apple not accepting it, as they scan programs for system calls. But I believe an open system call is fine.


worked code for me:

#include <fcntl.h>- (BOOL) openFile:(NSString *)filePath ......{...const char * filePathStr = [filePath UTF8String];int fd = open(filePathStr, O_RDONLY);...}