title: How does strnlen work in C++?
body: <p>I'm confused how <code>strnlen</code> could work in C++ with strings that weren't null terminated, as I 'm not sure how it computes the size. An <code>strlen</code> implementation is easy:</p>
  
  <pre><code>size_t strlen(char *s)
  {
      size_t sz;
      while(*s++ != '\0')
      {
          ++sz;
      }
      return sz;
  }
  </code></pre>
  
  <p>But how would you implement <code>strnlen()</code>?</p>