title: trigger function before file write operation
body: <p>Let say we have a function:</p>
  
  <pre><code>void persist_result(FILE* to, unsigned char* b, int b_len) {...}
  </code></pre>
  
  <p>which would save some result in the given <code>FILE* to</code>.</p>
  
  <p>Now I would like to get the data before the data is written to <code>to</code>, do something with it (assume encrypt it, etc..) and then call the actual IO operation, directly or indirectly.</p>
  
  <p>One solution could be setting a buffer, but I don't know how to trigger my method for the encryption operation.</p>
  
  <p>Also I was thinking to get some handle of file in memory, but don't know if there is any ISO way to do that?</p>
  
  <p>Or any better solution?</p>
  
  <p>Consider the following:</p>
  
  <ol>
  <li>Size of the data need to be written by the <code>persist_result</code> is unknown, it could be 1 or more bytes.</li>
  <li>I cannot change the source of <code>persist_result</code>.</li>
  <li>No C++; it must be a portable C solution.</li>
  </ol>