Writing an itoa function Here is a basic itoa function that I've written trying to use recursion:
void itoa(int number, char buffer[])
{
    static int idx=0, size=0;
    if (number == 0) {
        buffer[size] = '\0';
        idx = size = 0; // reset for next call
    }
    else {
        size++, idx++;
        itoa(number/10, buffer);
        buffer[size-idx--] = (number % 10) + '0';
    }
}

How does it look? It is not thread-safe due to the static, but is that an issue for a function such as this? If so, how could I update that? What other ways could I make improvements to it?
How does it look?

Not so good.

Not thread safe.

Does not handle negative numbers well.

Forms &quot;&quot; with 0.

Prone to buffer overflow.

itoa() is not a standard function, yet it commonly returns a pointer.


A test harness
int main(void) {
  char buf[100];
  int test[] = {123, 456, 0, - 42, INT_MAX, INT_MIN};
  int n = sizeof test / sizeof *test;
  for (int i = 0; i &lt; n; i++) {
    itoa(test[i], buf);
    printf(&quot;%-11d &lt;%s&gt;\n&quot;, test[i], buf);
  }
  return 0;
}

Output
123         &lt;123&gt;
456         &lt;456&gt;
0           &lt;&gt;
-42         &lt;,.&gt;
2147483647  &lt;2147483647&gt;
-2147483648 &lt;./,),(-*,(&gt;



It is not thread-safe due to the static, but is that an issue for a function such as this?

Yes.  Thread safety is expected.


If so, how could I update that? What other ways could I make improvements to it?

I really do not think this is a good place to use recursion given the potential for buffer overflow is a fair complication.
But if one must use recursion, consider adding error checking and test for various sorts of int including 0, INT_MAX, INT_MIN.
static char* itoa_helper(int number, size_t sz, char buffer[]) {
  if (sz == 0) {
    return NULL;
  }
  if (number &lt;= -10) {
    buffer = itoa_helper(number / 10, sz - 1, buffer);
    if (buffer == NULL) {
      return NULL;
    }
    number %= 10;
  }
  *buffer = (char) ('0' - number);
  return buffer + 1;
}

char* itoa_recursive_alt(int number, size_t sz, char buffer[sz]) {
  if (sz == 0 || buffer == NULL) {
    return NULL;
  }
  char *s = buffer;

  if (number &gt;= 0) {
    // Flip pos numbers to neg as neg range is greater.
    number = -number;
  } else {
    sz--;
    if (sz == 0) {
      *buffer = '\0';
      return NULL;
    }
    *s++ = '-';
  }
  s = itoa_helper(number, sz-1, s);
  if (s == NULL) {
    *buffer = '\0';
    return NULL;
  }
  *s = 0;
  return buffer;
}

int main(void) {
  char buf[100];
  int test[] = {123, 456, 0, -42, INT_MAX, INT_MIN};
  int n = sizeof test / sizeof *test;
  for (int i = 0; i &lt; n; i++) {
    // char *s = itoa_recursive_alt(test[i], sizeof buf, buf);
    char *s = itoa_recursive_alt(test[i], sizeof buf, buf);
    if (s == NULL)
      s = &quot;NULL&quot;;
    printf(&quot;%-11d &lt;%s&gt; &lt;%s&gt;\n&quot;, test[i], s, buf);
  }
  return 0;
}

Output
123         &lt;123&gt; &lt;123&gt;
456         &lt;456&gt; &lt;456&gt;
0           &lt;0&gt; &lt;0&gt;
-42         &lt;-42&gt; &lt;-42&gt;
2147483647  &lt;2147483647&gt; &lt;2147483647&gt;
-2147483648 &lt;-2147483648&gt; &lt;-2147483648&gt;