-
-
Save jverkoey/2985830 to your computer and use it in GitHub Desktop.
| const char* cstr = [string UTF8String]; | |
| void* anon = mmap(0, sizeof(char) * (string.length + 1), PROT_WRITE|PROT_READ, MAP_ANON|MAP_PRIVATE, 0, 0); | |
| if (anon == MAP_FAILED) { | |
| NSLog(@"Failed to map memory."); | |
| return; | |
| } | |
| strcpy(anon, cstr); | |
| // How do I get a file descriptor for use here? | |
| markdownin = fdopen(fd, "r"); |
Here's the latest. Still not working sadly and I'm not sure what the culprit is.
const char* path = "/string1524";
int stringSize = sizeof(char) * (string.length + 1);
int fd = shm_open(path, O_RDWR | O_CREAT);
ftruncate(fd, stringSize);
void* anon = mmap(0, stringSize, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
if (anon == MAP_FAILED) {
NSLog(@"Failed to map memory.");
}
strcpy(anon, cstr);
// This returns a FILE*, but when trying to read from it I get garbage data.
markdownin = fdopen(fd, "r");
Unfortunately I also in result had no success in making it work on OS X / iOS.
However I found alternative solution which even isn't an ugly hack – http://developer.apple.com/library/ios/#documentation/System/Conceptual/ManPages_iPhoneOS/man3/fropen.3.html
You can just specify your function to read stream.
There is example here https://redmine.openinfosecfoundation.org/attachments/105/0001-fmemopen-wrapper-added-fix-compilation-problems-on-m.patch
I used this code linked to by poTomek on twitter and it worked beautifully:
https://github.com/ingenuitas/python-tesseract/blob/master/fmemopen.c
Looks very similar to the example given in your links :)
http://jverkoey.github.com/fmemopen/
Thanks gang!
shm_opento obtain file descriptor.shm_openinmmap.fdopento obtainFILEpointer from file descriptor.