fixed xulong/xlong declarations
[util-vserver.git] / util-vserver / lib / fmt.h
1 // $Id$    --*- c -*--
2
3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 //  
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.
8 //  
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.
13 //  
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.
17
18
19 #ifndef H_VSERVER_DJINNI_SRC_FMT_H
20 #define H_VSERVER_DJINNI_SRC_FMT_H
21
22 #include <stdlib.h>
23 #include <stdint.h>
24
25 #ifndef FMT_PREFIX
26 #  define FMT_PREFIX    fmt_
27 #endif
28
29 #define FMT_P__(X,Y)    X ## Y
30 #define FMT_P_(X,Y)     FMT_P__(X,Y)
31 #define FMT_P(X)        FMT_P_(FMT_PREFIX, X)
32
33 #define STRINGIFY_(X)   #X
34 #define STRINGIFY(X)    STRINGIFY_(X)
35 #define WEAKFUNC(X)     __attribute__((__weak__,__alias__(STRINGIFY(FMT_P(X)))))
36
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 size_t  FMT_P(xuint64)(char *ptr, uint_least64_t val);
43 size_t  FMT_P( xint64)(char *ptr,  int_least64_t val);
44
45 size_t  FMT_P(xuint32)(char *ptr, uint_least32_t val);
46 size_t  FMT_P( xint32)(char *ptr,  int_least32_t val);
47   
48 size_t  FMT_P(uint64_base)(char *ptr, uint_least64_t val, char base);
49 size_t  FMT_P( int64_base)(char *ptr,  int_least64_t val, char base);
50
51 size_t  FMT_P(uint32_base)(char *ptr, uint_least32_t val, char base);
52 size_t  FMT_P( int32_base)(char *ptr,  int_least32_t val, char base);
53
54 #if __WORDSIZE == 64
55 size_t  FMT_P(ulong_base)(char *ptr, unsigned long val, char base) WEAKFUNC(uint64_base);
56 size_t  FMT_P( long_base)(char *ptr,          long val, char base) WEAKFUNC( int64_base);
57 size_t  FMT_P(xulong)    (char *ptr, unsigned long val)            WEAKFUNC(xuint64);
58 size_t  FMT_P( xlong)    (char *ptr,          long val)            WEAKFUNC( xint64);
59 #else
60 size_t  FMT_P(ulong_base)(char *ptr, unsigned long val, char base) WEAKFUNC(uint32_base);
61 size_t  FMT_P( long_base)(char *ptr,          long val, char base) WEAKFUNC( int32_base);
62 size_t  FMT_P(xulong)    (char *ptr, unsigned long val)            WEAKFUNC(xuint32);
63 size_t  FMT_P( xlong)    (char *ptr,          long val)            WEAKFUNC( xint32);
64 #endif
65
66 size_t  FMT_P(uint_base)(char *ptr, unsigned int val, char base)   WEAKFUNC(uint32_base);
67 size_t  FMT_P( int_base)(char *ptr,          int val, char base)   WEAKFUNC( int32_base);
68 size_t  FMT_P(xuint)    (char *ptr, unsigned int val, char base)   WEAKFUNC(xuint32);
69 size_t  FMT_P( xint)    (char *ptr,          int val, char base)   WEAKFUNC( xint32);
70
71
72 inline static size_t
73 FMT_P(ulong)(char *ptr, unsigned long val)
74 {
75   return FMT_P(ulong_base)(ptr, val, 10);
76 }
77
78 inline static size_t
79 FMT_P(long)(char *ptr, long val)
80 {
81   return FMT_P(long_base)(ptr, val, 10);
82 }
83
84
85 inline static size_t
86 FMT_P(uint)(char *ptr, unsigned int val)
87 {
88   return FMT_P(uint_base)(ptr, val, 10);
89 }
90
91 inline static size_t
92 FMT_P(int)(char *ptr, int val)
93 {
94   return FMT_P(int_base)(ptr, val, 10);
95 }
96
97
98 #ifdef __cplusplus
99 }
100 #endif
101
102 #undef WEAKFUNC
103 #undef STRINGIFY
104 #undef STRINGIFY_
105 #undef FMT_P
106 #undef FMT_P_
107 #undef FMT_P__
108
109 #endif  //  H_VSERVER_DJINNI_SRC_FMT_H