File: itoa.cc

package info (click to toggle)
nullmailer 1%3A1.03-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,524 kB
  • ctags: 695
  • sloc: cpp: 4,484; sh: 4,123; makefile: 224; perl: 184
file content (23 lines) | stat: -rw-r--r-- 391 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "itoa.h"

const char *itoa(long v, int digits)
{
  static char buf[INTLENGTH];
  bool neg = false;
  if(v < 0) {
    v = -v;
    neg = true;
  }
  char* ptr = buf + INTLENGTH;
  *--ptr = '\0';
  do {
    *--ptr = (v % 10) + '0';
    v /= 10;
    --digits;
  } while(v != 0);
  while(digits > 0 && ptr > buf-1)
    *--ptr = '0', --digits;
  if(neg)
    *--ptr = '-';
  return ptr;
}