title: What is the rationale for not including strdup in the C Standard?
body: <p>Most C programmers are familiar with the <code>strdup</code> function.  Many of them will take it for granted, yet it is not part of the C Standard (neither C89, C99 nor C11).  It is part of POSIX and may not be available on all environments.  Indeed Microsoft insisted on renaming it <code>_strdup</code>, adding to confusion.</p>
  
  <p>It is rather easy to define it this way (in C):</p>
  
  <pre><code>#include &lt;string.h&gt;
  
  char *strdup(const char *s) {
      size_t size = strlen(s) + 1;
      char *p = malloc(size);
      if (p) {
          memcpy(p, s, size);
      }
      return p;
  }
  </code></pre>
  
  <p>But even savvy programmers can easily get it wrong.</p>
  
  <p>Furthermore, redefining the function only on systems that do not have it proves a bit complicated as explained here: <a href="https://stackoverflow.com/questions/482375/strdup-function">strdup() function</a></p>
  
  <p>Why not include such useful widely supported functions in revised editions of the C Standard?  A lot of new functions have been added in the C standard library in C99, what is the rationale for not including <code>strdup</code>?</p>