merge with 0.30.213
[util-vserver.git] / ensc_fmt / fmt.h
1 // $Id: fmt.h 1890 2005-03-17 14:46:19Z ensc $    --*- 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 /** \file   fmt.h
19  *  \brief  Declarations for some fmt_* functions
20  */
21
22 #ifndef H_ENSC_FMT_FMT_H
23 #define H_ENSC_FMT_FMT_H
24
25 #include <stdlib.h>
26 #include <stdint.h>
27
28 #ifndef FMT_PREFIX
29 #  define FMT_PREFIX    fmt_
30 #endif
31
32 #define FMT_P__(X,Y)    X ## Y
33 #define FMT_P_(X,Y)     FMT_P__(X,Y)
34 #define FMT_P(X)        FMT_P_(FMT_PREFIX, X)
35
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 size_t  FMT_P(xuint64)(char *ptr, uint_least64_t val);
42 size_t  FMT_P( xint64)(char *ptr,  int_least64_t val);
43
44 size_t  FMT_P(xuint32)(char *ptr, uint_least32_t val);
45 size_t  FMT_P( xint32)(char *ptr,  int_least32_t val);
46   
47 size_t  FMT_P(uint64_base)(char *ptr, uint_least64_t val, char base);
48 size_t  FMT_P( int64_base)(char *ptr,  int_least64_t val, char base);
49
50 size_t  FMT_P(uint32_base)(char *ptr, uint_least32_t val, char base);
51 size_t  FMT_P( int32_base)(char *ptr,  int_least32_t val, char base);
52
53 size_t  FMT_P(ulong_base)(char *ptr, unsigned long val, char base);
54 size_t  FMT_P( long_base)(char *ptr,          long val, char base);
55 size_t  FMT_P(xulong)    (char *ptr, unsigned long val);
56 size_t  FMT_P( xlong)    (char *ptr,          long val);
57
58 size_t  FMT_P(uint_base)(char *ptr, unsigned int val, char base);
59 size_t  FMT_P( int_base)(char *ptr,          int val, char base);
60 size_t  FMT_P(xuint)    (char *ptr, unsigned int val);
61 size_t  FMT_P( xint)    (char *ptr,          int val);
62
63 struct timeval;
64 size_t  FMT_P(tai64n)(char *ptr, struct timeval const *now);
65
66 inline static size_t
67 FMT_P(uint64)(char *ptr, uint_least64_t val)
68 {
69   return FMT_P(uint64_base)(ptr, val, 10);
70 }
71
72 inline static size_t
73 FMT_P(int64)(char *ptr, uint_least64_t val)
74 {
75   return FMT_P(int64_base)(ptr, val, 10);
76 }
77
78 inline static size_t
79 FMT_P(uint32)(char *ptr, uint_least32_t val)
80 {
81   return FMT_P(uint32_base)(ptr, val, 10);
82 }
83
84 inline static size_t
85 FMT_P(int32)(char *ptr, uint_least32_t val)
86 {
87   return FMT_P(int32_base)(ptr, val, 10);
88 }
89
90 inline static size_t
91 FMT_P(ulong)(char *ptr, unsigned long val)
92 {
93   return FMT_P(ulong_base)(ptr, val, 10);
94 }
95
96 inline static size_t
97 FMT_P(long)(char *ptr, long val)
98 {
99   return FMT_P(long_base)(ptr, val, 10);
100 }
101
102
103 inline static size_t
104 FMT_P(uint)(char *ptr, unsigned int val)
105 {
106   return FMT_P(uint_base)(ptr, val, 10);
107 }
108
109 inline static size_t
110 FMT_P(int)(char *ptr, int val)
111 {
112   return FMT_P(int_base)(ptr, val, 10);
113 }
114
115
116 #ifdef __cplusplus
117 }
118 #endif
119
120 #undef FMT_P
121 #undef FMT_P_
122 #undef FMT_P__
123
124 #endif  //  H_ENSC_FMT_FMT_H