X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Flib%2Ffmt.hc;h=4472df18c1b0b4623e2d203da05d0210f59bdd99;hb=462c8268093c2b86d36139a50296c125e48cc81f;hp=25273f46c4509537731c570e35a07518b82dbb99;hpb=40730f8dcef5467014a2cb830aa03bd800d6056c;p=util-vserver.git diff --git a/util-vserver/lib/fmt.hc b/util-vserver/lib/fmt.hc index 25273f4..4472df1 100644 --- a/util-vserver/lib/fmt.hc +++ b/util-vserver/lib/fmt.hc @@ -21,51 +21,17 @@ #endif #include "fmt.h" +#include "fmt-internal.h" #include -static char const DIGITS[] = "0123456789abcdefghijklmnopqrstuvwxyz"; - -#define FMT_P__(X,Y) X ## Y -#define FMT_P_(X,Y) FMT_P__(X,Y) -#define FMT_P(X) FMT_P_(FMT_PREFIX, X) - -#define CONCAT__(x,y,z) x ## y ## z -#define CONCAT_(x,y,z) CONCAT__(x,y,z) -#define CONCAT(x,z) CONCAT_(x, FMT_BITSIZE, z) - -#define FMT_FN(BASE,SZ) \ - do { \ - register __typeof__(val) v = val; \ - register size_t l = 0; \ - \ - if (ptr==0) { \ - do { \ - ++l; \ - v /= BASE; \ - } while (v!=0); \ - } \ - else { \ - char buf[sizeof(val)*SZ]; \ - \ - do { \ - register unsigned int d = v%BASE; \ - v /= BASE; \ - ++l; \ - buf[sizeof(buf)-l] = DIGITS[d]; \ - } while (v!=0); \ - \ - memcpy(ptr, buf+sizeof(buf)-l, l); \ - } \ - \ - return l; \ - } while (0) +#define STRINGIFY_(X) #X +#define STRINGIFY(X) STRINGIFY_(X) +#define ALIASFUNC(X) __attribute__((__alias__(STRINGIFY(FMT_P(X))))) size_t CONCAT(FMT_P(uint),_base)(char *ptr, CONCAT(uint_least,_t) val, char base) { - //if (base==10) FMT_FN(10,3); - if (base==16) FMT_FN(16,2); - + if (base==16) return CONCAT(FMT_P(xuint),)(ptr,val); FMT_FN(base,8); }