aboutsummaryrefslogtreecommitdiff
path: root/djb/fmt_ulong.c
blob: dfd7f9e34b9e2e5f05a31c56e1d70f32218b3c3e (plain)
1
2
3
4
5
6
7
8
9
10
unsigned int fmt_ulong(char *s, unsigned long u) /*EXTRACT_INCL*/ {
  register unsigned int len; register unsigned long q;
  len = 1; q = u;
  while (q > 9) { ++len; q /= 10; }
  if (s) {
    s += len;
    do { *--s = '0' + (u % 10); u /= 10; } while(u); /* handles u == 0 */
  }
  return len;
}