title: Is it safe to assume errno to be always positive?
body: <p>I am writing a program in which most of the used library functions <strong>return -1 on error and set errno</strong>. The behaviour of the program is such that it exits if error occurs. To determine exact exit point and the error from outside the program (example using <code>gdb</code>), I want to use following method:</p>
  
  <pre class="lang-c prettyprint-override"><code>err = func_1(..arglist_1..);
  if(err != 0)
  {
      perror("func(..arglist..)");
      return ((1u &lt;&lt; 8) | errno);
  }
  //..
  //.. some more funcs
  //..
  err = func_n(..arglist_n..);
  if(err != 0)
  {
      perror("func(..arglist_n..)");
      return (((unsigned)n &lt;&lt; 8) | errno);
  }
  </code></pre>
  
  <p>The problem here is safe assumptions.  </p>
  
  <p><strong>Reality:</strong>  <em>errno</em> is declared as <code>extern int errno;</code> inside <code>errno.h</code><br>
  <strong>Assumption 1:</strong> Value of <em>errno</em> is always less than 255.<br>
  <strong>Assumption 2:</strong> <em>errno</em> is always positive.</p>
  
  <p>On the basis of all the error constants (EAGAIN, etc) defined in <code>errno.h</code>, these assumptions are true at present. Can these be assumed to be true in future also?</p>
  
  <p>P.S.: I do not want to depend on <code>perror()</code> to determine exit point.</p>