added/use specialized hex-formating functions
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Thu, 20 Nov 2003 18:05:17 +0000 (18:05 +0000)
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Thu, 20 Nov 2003 18:05:17 +0000 (18:05 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@427 94cd875c-1c1d-0410-91d2-eb244daf1a30

util-vserver/lib/fmt.h
util-vserver/lib/fmt.hc

index e869829..f6d84c6 100644 (file)
 extern "C" {
 #endif
 
+size_t FMT_P(xuint64)(char *ptr, uint_least64_t val);
+size_t FMT_P( xint64)(char *ptr,  int_least64_t val);
+
+size_t FMT_P(xuint32)(char *ptr, uint_least32_t val);
+size_t FMT_P( xint32)(char *ptr,  int_least32_t val);
+  
 size_t FMT_P(uint64_base)(char *ptr, uint_least64_t val, char base);
 size_t FMT_P( int64_base)(char *ptr,  int_least64_t val, char base);
 
@@ -48,13 +54,19 @@ size_t      FMT_P( int32_base)(char *ptr,  int_least32_t val, char base);
 #if __WORDSIZE == 64
 size_t FMT_P(ulong_base)(char *ptr, unsigned long val, char base) WEAKFUNC(uint64_base);
 size_t FMT_P( long_base)(char *ptr,          long val, char base) WEAKFUNC( int64_base);
+size_t FMT_P(xulong)    (char *ptr, unsigned long val)            WEAKFUNC(xuint64);
+size_t FMT_P( xlong)    (char *ptr,          long val)            WEAKFUNC( xint64);
 #else
 size_t FMT_P(ulong_base)(char *ptr, unsigned long val, char base) WEAKFUNC(uint32_base);
 size_t FMT_P( long_base)(char *ptr,          long val, char base) WEAKFUNC( int32_base);
+size_t FMT_P(xulong)    (char *ptr, unsigned long val, char base) WEAKFUNC(xuint32);
+size_t FMT_P( xlong)    (char *ptr,          long val, char base) WEAKFUNC( xint32);
 #endif
 
-size_t FMT_P(uint_base)(char *ptr, unsigned int val, char base) WEAKFUNC(uint32_base);
-size_t FMT_P( int_base)(char *ptr,          int val, char base) WEAKFUNC( int32_base);
+size_t FMT_P(uint_base)(char *ptr, unsigned int val, char base)   WEAKFUNC(uint32_base);
+size_t FMT_P( int_base)(char *ptr,          int val, char base)   WEAKFUNC( int32_base);
+size_t FMT_P(xuint)    (char *ptr, unsigned int val, char base)   WEAKFUNC(xuint32);
+size_t FMT_P( xint)    (char *ptr,          int val, char base)   WEAKFUNC( xint32);
 
 
 inline static size_t
index 25273f4..6a03e54 100644 (file)
 #endif
 
 #include "fmt.h"
+#include "fmt-internal.h"
 #include <string.h>
 
-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)
-
 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);
 }