File: itoa.cc

package info (click to toggle)
plotutils 2.4.1-15
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 11,072 kB
  • ctags: 6,952
  • sloc: ansic: 76,305; cpp: 12,402; sh: 8,475; yacc: 2,604; makefile: 894; lex: 144
file content (33 lines) | stat: -rw-r--r-- 624 bytes parent folder | download | duplicates (13)
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
/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
     Written by James Clark (jjc@jclark.com) */

#include "lib.h"

#define INT_DIGITS 19		/* enough for 64 bit integer */

const char *
our_itoa(int i)
{
  /* Room for INT_DIGITS digits, - and '\0' */
  static char buf[INT_DIGITS + 2];
  char *p = buf + INT_DIGITS + 1; /* points to terminating '\0' */
  if (i >= 0) 
    {
      do 
	{
	  *--p = '0' + (i % 10);
	  i /= 10;
	} while (i != 0);
      return p;
    }
  else 
    {				/* i < 0 */
      do 
	{
	  *--p = '0' - (i % 10);
	  i /= 10;
	} while (i != 0);
      *--p = '-';
    }
  return p;
}