 <p>It turns out there is H_SAVE_FP which saves files to an opened file pointer.</p> <p>The code then looks like:</p> <pre><code>FILE* fp = fopen("historyfile", "w"); ... cap_enter(); ... history(inhistory, &amp;ev, H_SAVE_FP, fp); </code></pre>