title: Proper/Efficient way to determine size of stdin in C
body: <p>Based on my previous question, what would be the proper yet efficient way to determine the size of <code>stdin</code> if stdin is coming from a <code>pipe</code> or a <code>terminal</code> on different systems.</p>
  
  <p>I was doing the following, however, based on some comments, it is not the right way, and it might or it might not work on different systems.</p>
  
  <pre><code>#include &lt;sys/stat.h&gt;
  
  off_t size(FILE *st_in) {
      struct stat st;
      if (fstat(fileno(st_in), &amp;st) == 0)
          return st.st_size;
      return -1;
  }
  </code></pre>