POK
itoa.c
1 /*
2  * POK header
3  *
4  * The following file is a part of the POK project. Any modification should
5  * made according to the POK licence. You CANNOT use this file or a part of
6  * this file is this part of a file for your own project
7  *
8  * For more information on the POK licence, please see our LICENCE FILE
9  *
10  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
11  *
12  * Copyright (c) 2007-2009 POK team
13  *
14  * Created by julien on Thu Jan 15 23:34:13 2009
15  */
16 
17 
18 #include <core/dependencies.h>
19 #include <libc/string.h>
20 
21 #ifdef POK_CONFIG_NEEDS_FUNC_ITOA
22 
23 __attribute__ ((weak))
24 char *itoa(int value, char *buff, int radix)
25 {
26  char temp[16];
27  int i = 0;
28  int j = 0;
29  unsigned int digit;
30  unsigned int uvalue;
31 
32  if ((radix == 10) && (value < 0))
33  {
34  uvalue = -value;
35  buff[j++] = '-';
36  }
37  else
38  uvalue = value;
39 
40  do
41  {
42  digit = uvalue % radix;
43  uvalue = (uvalue - digit)/radix;
44  if (digit < 10)
45  temp[i++] = (char)('0' + digit);
46  else
47  temp[i++] = (char)('a' + (digit - 10));
48  }
49  while (uvalue != 0);
50  --i;
51  do
52  buff[j++] = temp[i--];
53  while (i >= 0);
54  buff[j] = '\0';
55  return buff;
56 }
57 
58 #endif
59