title: Detect NUL file descriptor (isatty is bogus)
body: <p>The following C file gives a bogus result when NUL is piped to it:</p>
  
  <pre><code>int main()
  {
    printf("_isatty = %d\n", _isatty(0));
  }
  </code></pre>
  
  <p>the result is:</p>
  
  <pre><code>C:\Users\Edward\Dev\nulltest&gt; test.exe &lt; NUL
  _isatty = 64
  </code></pre>
  
  <p>I'm pretty sure NUL (aka /dev/null) is not a terminal device! So I need to detect in another way whether or not the file descriptor corresponds to NUL. The number doesn't have any specific meaning; I see it when I actually do have a terminal attached.</p>
  
  <p>What should I do? <a href="https://stackoverflow.com/questions/926865/isatty-on-windows-ce">This question</a> suggests using a sketchy undocumented function to get the underlying name, presumably comparing it to NUL, but that feels less than ideal to me. Is there a better way?</p>
  
  <p>P.S. This would help solve <a href="http://hackage.haskell.org/trac/ghc/ticket/2628" rel="nofollow noreferrer">this GHC bug</a>.</p>