Reputation: 1135
I have the following code which I call from a Swift main program in Xcode and when running it in the Simulator in a virtual iPhone for example, it works. It creates /tmp/MYFIFO
.
int32_t init_udpC(void) {
static char *filename="/tmp/MYFIFO";
umask(0);
unlink(filename);
if((mkfifo(filename, 0666)) == -1){
perror("mkfifo");
exit(2);
}
if((fd=open("/tmp/MYFIFO",O_RDWR|O_APPEND)) == -1) {
perror("open");
exit(2);
}
return fd;
}
Running it on the physical device the code fails with
mkfifo: Operation not permitted
Upvotes: 0
Views: 1111
Reputation: 70976
It's because of iOS sandboxing. On iOS, your app isn't allowed to access /tmp/
. It works in the simulator because you're running on macOS, where it's OK.
You need to use a path that's someplace where your app is allowed to access. One possibility is to replace the path with
const char *filename=[[NSTemporaryDirectory() stringByAppendingPathComponent:@"MYFIFO"] UTF8String];
There are other valid paths-- the key is that you have to be allowed to access the directory.
Upvotes: 2