title: Cross-platform access to C constants
body: <p>Is there a cross-platform (ie, across Linux, BSD, &amp; OS X, ideally all of POSIX) I can get programmatic access to constants like <code>O_RDWR</code>, based purely on the string <code>"O_RDWR"</code>?  I am writing some (non-C) code that interoperates with C functions across platforms and needs to call, eg, open(2) with the correct parameters - but I have no guarantee as far as what the local system sets its constants to.</p>
  
  <p>I'm essentially looking for something like <code>get_constant_value("O_RDWR") -&gt; "02"</code>.</p>
  
  <p>EDIT:
  I currently have a really nasty hack: directly invoke the preprocessor and examine the output.</p>
  
  <pre><code>printf "#include &lt;fcntl.h&gt;\nO_RDWR" | cpp | tail -n 1
  </code></pre>