* Christmas edition *; fixed irc /os command; small cleanup in fd.c; improvements...
[ZeXOS.git] / libc / stdlib / itoa.c
blobd3020e4c1e39bae05076f773022a06f237d0d50b
1 /*
2 * ZeX/OS
3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <string.h>
21 char *itoa (int value, char *string, int radix)
23 char buf[16];
24 char * where = buf + 16 - 1;
25 *where = '\0';
29 unsigned long temp = (unsigned long)value % radix;
30 where--;
31 if(temp < 10)
32 *where = temp + '0';
33 else
34 *where = temp - 10 + 'a';
35 value = (unsigned long)value / radix;
37 while(value != 0);
39 unsigned l = strlen (where);
40 memcpy (string, where, l);
41 string [l] = '\0';
43 return string;