title: Are open streams automatically flushed and closed on SIGINT in C?
body: <p>I've read in a man page that when <code>exit()</code> is called all streams are flushed and closed automatically. At first I was skeptical as to how this was done and whether it is truly reliable but seeing as I can't find out any more I'm going to accept that it just works — we'll see if anything blows up. Anyway, if this stream closing behavior is present in <code>exit()</code> is such behavior also present in the default handler for <code>SIGINT</code> (the interrupt signal usually triggered with Ctrl+C)? Or, would it be necessary to do something like this:</p>
  
  <pre><code>#include &lt;signal.h&gt;
  #include &lt;stdlib.h&gt;
  
  void onInterrupt(int dummy) { exit(0); }
  
  int main() {
     signal(SIGINT, onInterrupt);
     FILE *file = fopen("file", "a");
     for (;;) { fprintf(file, "bleh"); } }
  </code></pre>
  
  <p>to get <code>file</code> to be closed properly? Or can the <code>signal(SIG...</code> and <code>void onInterrupt(...</code> lines be safely omitted?</p>
  
  <p>Please restrict any replies to C, C99, and POSIX as I'm not using GNU libc. Thanks.</p>