title: What size should I allow for strerror_r?
body: <p>The OpenGroup POSIX.1-2001 defines <a href="http://www.opengroup.org/onlinepubs/000095399/functions/strerror.html" rel="noreferrer">strerror_r</a>, as does <a href="http://refspecs.freestandards.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/baselib-strerror-r.html" rel="noreferrer">The Linux Standard Base Core Specification 3.1</a>.  But I can find no reference to the maximum size that could be reasonably expected for an error message. I expected some define somewhere that I could put in my code but there is none that I can find.</p>
  
  <p><em>The code must be thread safe.</em> Which is why strerror_r is used and not strerror.</p>
  
  <p>Does any one know the symbol I can use? I should I create my own?</p>
  
  <hr>
  
  <h2>Example</h2>
  
  <pre><code>int result = gethostname(p_buffy, size_buffy);
  int errsv = errno;
  if (result &lt; 0)
  {
      char buf[256];
      char const * str = strerror_r(errsv, buf, 256);
      syslog(LOG_ERR,
               "gethostname failed; errno=%d(%s), buf='%s'",
               errsv,
               str,
               p_buffy);
       return errsv;
  }
  </code></pre>
  
  <hr>
  
  <p><strong>From the documents:</strong></p>
  
  <p>The Open Group Base Specifications Issue 6:</p>
  
  <blockquote>
    <p><strong>ERRORS</strong></p>
    
    <p>The strerror_r() function may fail if:</p>
    
    <ul>
    <li><strong>[ERANGE]</strong> Insufficient storage was supplied via strerrbuf and buflen to
    contain the generated message string.</li>
    </ul>
  </blockquote>
  
  <hr>
  
  <p><strong>From the source:</strong></p>
  
  <p>glibc-2.7/glibc-2.7/string/strerror.c:41:</p>
  
  <pre><code>    char *
      strerror (errnum)
           int errnum;
      {
          ...
          buf = malloc (1024);
  </code></pre>