title: Clearing buffer on fread() from fifo in C?
body: <p>I am reading continuous data (lines of text/strnigs) from a FIFO using C function <code>fread()</code>. Now I noticed that my process is growing bigger and bigger in ram. Can I somehow flush the buffer of the <code>fopen()</code>handle?
  I can circumvent my process from growing if I do <code>fclose()</code> and subsequent <code>fopen()</code> after every line read, but is this really the solution?</p>
  
  <pre><code>int main() {
      unsigned char buffer[1];
  
      instream=fopen("/path/to/fifo", "r");
      if (instream!=NULL) {
          while (fread(&amp;buffer, 1, 1, instream)==1) {
              // ...
          }
      }
      else {
          // error handling...
      }
  
      return 0;
  }
  </code></pre>
  
  <p>This works, but seems ugly and error prone?</p>
  
  <pre><code>int main() {
      unsigned char buffer[1];
  
      instream=fopen("/path/to/fifo", "r");
      if (instream!=NULL) {
          while (fread(&amp;buffer, 1, 1, instream)==1) {
              // ...
  
          if (buffer[0] == '\n') {
              fclose(instream);
              instream=fopen("/path/to/fifo", "r");
          }
      }
      else {
          // error handling...
      }
  
      return 0;
  }
  </code></pre>
  
  <p>One additional question: is there a risk that my program reads faster than the output of the other program that writes into the fifo, and so <code>fread(...)</code> will be <code>0</code> and the <code>while</code>-loop will end?</p>