Possible Duplicate:
How to get file descriptor of buffer in memory?
I'm trying to force a library that uses a FILE
class to use a buffer in memory instead of a file. I tried fmemopen
, however, the library uses fileno
which returns -1 and causes the library to crash. So I read that I need a file descriptor and I could use the pipe command to make one. I don't fully understand what I did but I got it to work. However, I don't know if what I did is actually safe. So here is the code:
int fstr[2];
pipe(fstr);
write(fstr[1], src, strlen(src));
close(fstr[1]);
FILE* file = fdopen( fstr[0], "r" );
So is this safe?