Created
January 18, 2013 03:02
-
-
Save micahpearlman/4562041 to your computer and use it in GitHub Desktop.
Use fmemopen to create a file descriptor (FILE) for data already in memory.
This file contains 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
Use fmemopen to create a file descriptor (FILE) for data already in memory. | |
see: http://www.kernel.org/doc/man-pages/online/pages/man3/fmemopen.3.html | |
for iOS/OSX version see: https://github.com/jverkoey/fmemopen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's important to note that fmemopen(); doesn't provide a file descriptor but rather a file pointer. If fileno() is used in order to retrive the actual file descriptor, it will return -1, since there is no file descriptor at all.
char buffer[128] = { 'a' }
FILE * fp = fmemopen(buffer, sizoef(128), "r+");
int fd = fileno(fp);
printf ("File descriptor: %d\n", fd);
it will print -1.