1 // $Id: fmt-internal.h 1647 2004-08-19 13:53:54Z ensc $ --*- c -*--
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.
19 #ifndef H_UTIL_VSERVER_LIB_FMT_COMMON_H
20 #define H_UTIL_VSERVER_LIB_FMT_COMMON_H
22 #define DIGITS "0123456789abcdefghijklmnopqrstuvwxyz"
24 #define FMT_P__(X,Y) X ## Y
25 #define FMT_P_(X,Y) FMT_P__(X,Y)
26 #define FMT_P(X) FMT_P_(FMT_PREFIX, X)
28 #define CONCAT__(x,y,z) x ## y ## z
29 #define CONCAT_(x,y,z) CONCAT__(x,y,z)
30 #define CONCAT(x,z) CONCAT_(x, FMT_BITSIZE, z)
32 #define FMT_FN(BASE,SZ) \
34 register __typeof__(val) v = val; \
35 register size_t l = 0; \
44 char buf[sizeof(val)*SZ]; \
47 register unsigned int d = v%BASE; \
50 buf[sizeof(buf)-l] = DIGITS[d]; \
53 memcpy(ptr, buf+sizeof(buf)-l, l); \
60 #endif // H_UTIL_VSERVER_LIB_FMT_COMMON_H