3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
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; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 static char const DIGITS[] = "0123456789abcdefghijklmnopqrstuvwxyz";
28 #define FMT_P__(X,Y) X ## Y
29 #define FMT_P_(X,Y) FMT_P__(X,Y)
30 #define FMT_P(X) FMT_P_(FMT_PREFIX, X)
32 #define CONCAT__(x,y,z) x ## y ## z
33 #define CONCAT_(x,y,z) CONCAT__(x,y,z)
34 #define CONCAT(x,z) CONCAT_(x, FMT_BITSIZE, z)
36 #define FMT_FN(BASE,SZ) \
38 register __typeof__(val) v = val; \
39 register size_t l = 0; \
48 char buf[sizeof(val)*SZ]; \
51 register unsigned int d = v%BASE; \
54 buf[sizeof(buf)-l] = DIGITS[d]; \
57 memcpy(ptr, buf+sizeof(buf)-l, l); \
64 CONCAT(FMT_P(uint),_base)(char *ptr, CONCAT(uint_least,_t) val, char base)
66 //if (base==10) FMT_FN(10,3);
67 if (base==16) FMT_FN(16,2);
73 CONCAT(FMT_P(int),_base)(char *ptr,
74 CONCAT(int_least,_t) val, char base)
85 return CONCAT(FMT_P(uint),_base)(ptr, val, base) + offset;