POK
/home/jaouen/pok_official/pok/trunk/libpok/libc/string/itoa.c
00001 /*
00002  *                               POK header
00003  * 
00004  * The following file is a part of the POK project. Any modification should
00005  * made according to the POK licence. You CANNOT use this file or a part of
00006  * this file is this part of a file for your own project
00007  *
00008  * For more information on the POK licence, please see our LICENCE FILE
00009  *
00010  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
00011  *
00012  *                                      Copyright (c) 2007-2009 POK team 
00013  *
00014  * Created by julien on Thu Jan 15 23:34:13 2009 
00015  */
00016 
00017 
00018 #include <core/dependencies.h>
00019 #include <libc/string.h>
00020 
00021 #ifdef POK_CONFIG_NEEDS_FUNC_ITOA
00022 
00023 __attribute__ ((weak))
00024 char            *itoa(int value, char *buff, int radix)
00025 {
00026   char temp[16];
00027   int i = 0;
00028   int j = 0;
00029   unsigned int digit;
00030   unsigned int uvalue;
00031 
00032   if ((radix == 10) && (value < 0))
00033   {
00034     uvalue = -value;
00035     buff[j++] = '-';
00036   }
00037   else
00038     uvalue = value;
00039 
00040   do
00041   {
00042     digit = uvalue % radix;
00043     uvalue = (uvalue - digit)/radix;
00044     if (digit < 10)
00045       temp[i++] = (char)('0' + digit);
00046     else
00047       temp[i++] = (char)('a' + (digit - 10));
00048   }
00049   while (uvalue != 0);
00050   --i;
00051   do
00052     buff[j++] = temp[i--];
00053   while (i >= 0);
00054   buff[j] = '\0';
00055   return buff;
00056 }
00057 
00058 #endif
00059