Is this code safe for opening a buffer in memory as a file?(Code appears to work)
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/1558772/how-to-get-file-descriptor-of-buffer-in-memory">How to get file descriptor of buffer in memory?</a>  </p>
</blockquote>



<p>I'm trying to force a library that uses a <code>FILE</code> class to use a buffer in memory instead of a file. I tried <code>fmemopen</code>, however, the library uses <code>fileno</code> 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:</p>

<pre><code>int fstr[2];
pipe(fstr);
write(fstr[1], src, strlen(src));
close(fstr[1]);
FILE* file = fdopen( fstr[0], "r" );
</code></pre>

<p>So is this safe?</p>
