title: Cross-platform compatibility of dprintf
body: <p>Linux has this nice function <a href="http://linux.die.net/man/3/dprintf" rel="nofollow noreferrer"><code>dprintf</code></a>:</p>
  
  <blockquote>
    <p>The functions <code>dprintf()</code> and <code>vdprintf()</code> (as found in the glibc2 library) are exact analogues of <code>fprintf()</code> and <code>vfprintf()</code>, except that they output to a file descriptor fd instead of to a given stream. </p>
  </blockquote>
  
  <p>however as that same source points out:</p>
  
  <blockquote>
    <p>These functions are GNU extensions, not in C or POSIX. Clearly, the names were badly chosen. Many systems (like MacOS) have incompatible functions called <code>dprintf()</code>, usually some debugging version of <code>printf()</code>, perhaps with a prototype like</p>
  </blockquote>
  
  <pre><code>void dprintf (int level, const char *format, ...);
  </code></pre>
  
  <blockquote>
    <p>where the first parameter is a debugging level (and output is to <code>stderr</code>). Moreover, <code>dprintf()</code> (or <code>DPRINTF</code>) is also a popular macro name for a debugging <code>printf</code>. So, probably, it is better to avoid this function in programs intended to be portable. </p>
  </blockquote>
  
  <h2>My question</h2>
  
  <p>How can I make a setup that will safely call the <code>dprintf</code> that I want, if it exists, or fail to compile with some reasonably sane error message if that function doesn't exist? I guess I'd do something like this:</p>
  
  <pre><code>#ifdef SOMETHING
      #define Dprintf dprintf
  #else
      #error "no dprintf"
  #endif
  </code></pre>
  
  <p>but I don't know what <code>SOMETHING</code> should be. I guess I could restrict it to just Linux but could I make it looser?</p>