Created
June 25, 2012 01:03
-
-
Save jverkoey/2985830 to your computer and use it in GitHub Desktop.
Memory mapping in Objective-C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); |
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!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's the latest. Still not working sadly and I'm not sure what the culprit is.