title: feeding data to C API expecting a filename
body: <p>I'm writing a straightforward C program on Linux and wish to use an existing library's API which expects data from a file.  I must feed it a file name as a const char*.  But i have data,  just like content of a file, already sitting in a buffer allocated on the heap.  There is plenty of RAM and we want high performance.  Wanting to avoid writing a temporary file to disk, what is a good way to feed the data to this API in a way that looks like a file?</p>
  
  <p>Here's a cheap pretend version of my code:</p>
  
  <p>marvelouslibrary.h:</p>
  
  <pre><code>int marvelousfunction(const char *filename);
  </code></pre>
  
  <p>normal-persons-usage.cpp, for which library was originally designed:</p>
  
  <pre><code>#include "marvelouslibrary.h"
  int somefunction(char *somefilename)
  {
      return marvelousfunction(somefilename);
  }
  </code></pre>
  
  <p>myprogram.cpp:</p>
  
  <pre><code>#include "marvelouslibrary.h"
  int one_of_my_routines() 
  {
      byte* stuff = new byte[1000000];
      // fill stuff[] with...stuff!
      // stuff[] holds same bytes as might be found in a file
  
      /* magic goes here: make filename referring to stuff[] */
  
     return marvelousfunction( ??? );
  }
  </code></pre>
  
  <p>To be clear, the marvelouslibrary does not offer any API functions that accept data by pointer; it can only read a file.   </p>
  
  <p>I thought of pipes and mkfifo(), but seems meant for communicating between processes. I am no expert at these things. Does a named pipe work okay read and written in the same process?  Is this a wise approach?   </p>
  
  <p>Or skip being clever, go with plan "B" which is to shuddup and just write a temp file.  However, i'd like to learn something new and find out what's possible in this situation, beside getting high performance.</p>