File: utoa2.c

package info (click to toggle)
bglibs 2.04%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,368 kB
  • sloc: ansic: 15,820; perl: 674; sh: 64; makefile: 26
file content (42 lines) | stat: -rw-r--r-- 530 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "fmt.h"

char* utoa2(unsigned long i, char* buf)
{
  if (i < 10)
    *buf = i + '0';
  else {
    buf = utoa2(i / 10, buf);
    *buf = (i % 10) + '0';
  }
  *++buf = 0;
  return buf;
}

#ifdef SELFTEST_MAIN
void test(unsigned long u)
{
  char buf[32];
  char* ptr;
  ptr = utoa2(u, buf);
  obuf_write(&outbuf, buf, ptr - buf);
  NL();
}

MAIN
{
  test(0);
  test(1);
  test(11);
  test(0x7fffffffUL);
  test(0x80000000UL);
  test(0xffffffffUL);
}
#endif
#ifdef SELFTEST_EXP
0
1
11
2147483647
2147483648
4294967295
#endif