File: fmt_number.h

package info (click to toggle)
ngetty 1.1-3.1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 392 kB
  • sloc: ansic: 1,588; makefile: 206; sh: 193; asm: 100
file content (16 lines) | stat: -rw-r--r-- 363 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#define fmt_number_macro(f,type,base) \
unsigned int f(char *s, type u) {\
  type tmp=u;\
  unsigned int len=0;\
  do { tmp /=base; ++len; } while(tmp);\
  if (s) {\
    s +=len;\
    do {\
      unsigned char c = u%base;\
      if (base <= 10) *--s = c+'0';\
      else *--s = (c<10) ? c+'0' : c-10+'a';\
      u /=base;\
    } while (u);\
  }\
  return len;\
}