aboutsummaryrefslogtreecommitdiff
path: root/include/xatonum.h
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-11-25 14:44:13 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-11-25 14:44:13 +0000
commited836cdc30642ddbecc286b279d461ca44135cbb (patch)
tree70735d4bd1e34de43aa3f8092446caf460bd2540 /include/xatonum.h
parent809a6e310443d0b5010c8b293cab0160608c1b02 (diff)
downloadbusybox-w32-ed836cdc30642ddbecc286b279d461ca44135cbb.tar.gz
busybox-w32-ed836cdc30642ddbecc286b279d461ca44135cbb.tar.bz2
busybox-w32-ed836cdc30642ddbecc286b279d461ca44135cbb.zip
regularize str -> num convertors
Diffstat (limited to 'include/xatonum.h')
-rw-r--r--include/xatonum.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/include/xatonum.h b/include/xatonum.h
new file mode 100644
index 000000000..cdb5e7393
--- /dev/null
+++ b/include/xatonum.h
@@ -0,0 +1,94 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * ascii-to-numbers implementations for busybox
4 *
5 * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
6 *
7 * Licensed under GPLv2, see file LICENSE in this tarball for details.
8 */
9
10/* Provides extern declarations of functions */
11#define DECLARE_STR_CONV(type, T, UT) \
12\
13unsigned type xstrto##UT##_range_sfx(const char *str, int b, unsigned type l, unsigned type u, const struct suffix_mult *sfx); \
14unsigned type xstrto##UT##_range(const char *str, int b, unsigned type l, unsigned type u); \
15unsigned type xstrto##UT##_sfx(const char *str, int b, const struct suffix_mult *sfx); \
16unsigned type xstrto##UT(const char *str, int b); \
17unsigned type xato##UT##_range_sfx(const char *str, unsigned type l, unsigned type u, const struct suffix_mult *sfx); \
18unsigned type xato##UT##_range(const char *str, unsigned type l, unsigned type u); \
19unsigned type xato##UT##_sfx(const char *str, const struct suffix_mult *sfx); \
20unsigned type xato##UT(const char *str); \
21type xstrto##T##_range_sfx(const char *str, int b, type l, type u, const struct suffix_mult *sfx) ;\
22type xstrto##T##_range(const char *str, int b, type l, type u); \
23type xato##T##_range_sfx(const char *str, type l, type u, const struct suffix_mult *sfx); \
24type xato##T##_range(const char *str, type l, type u); \
25type xato##T##_sfx(const char *str, const struct suffix_mult *sfx); \
26type xato##T(const char *str); \
27
28/* Unsigned long long functions always exist */
29DECLARE_STR_CONV(long long, ll, ull)
30
31
32/* Provides extern inline definitions of functions */
33/* (useful for mapping them to the type of the same width) */
34#define DEFINE_EQUIV_STR_CONV(narrow, N, W, UN, UW) \
35\
36extern inline \
37unsigned narrow xstrto##UN##_range_sfx(const char *str, int b, unsigned narrow l, unsigned narrow u, const struct suffix_mult *sfx) \
38{ return xstrto##UW##_range_sfx(str, b, l, u, sfx); } \
39extern inline \
40unsigned narrow xstrto##UN##_range(const char *str, int b, unsigned narrow l, unsigned narrow u) \
41{ return xstrto##UW##_range(str, b, l, u); } \
42extern inline \
43unsigned narrow xstrto##UN##_sfx(const char *str, int b, const struct suffix_mult *sfx) \
44{ return xstrto##UW##_sfx(str, b, sfx); } \
45extern inline \
46unsigned narrow xstrto##UN(const char *str, int b) \
47{ return xstrto##UW(str, b); } \
48extern inline \
49unsigned narrow xato##UN##_range_sfx(const char *str, unsigned narrow l, unsigned narrow u, const struct suffix_mult *sfx) \
50{ return xato##UW##_range_sfx(str, l, u, sfx); } \
51extern inline \
52unsigned narrow xato##UN##_range(const char *str, unsigned narrow l, unsigned narrow u) \
53{ return xato##UW##_range(str, l, u); } \
54extern inline \
55unsigned narrow xato##UN##_sfx(const char *str, const struct suffix_mult *sfx) \
56{ return xato##UW##_sfx(str, sfx); } \
57extern inline \
58unsigned narrow xato##UN(const char *str) \
59{ return xato##UW(str); } \
60extern inline \
61narrow xstrto##N##_range_sfx(const char *str, int b, narrow l, narrow u, const struct suffix_mult *sfx) \
62{ return xstrto##W##_range_sfx(str, b, l, u, sfx); } \
63extern inline \
64narrow xstrto##N##_range(const char *str, int b, narrow l, narrow u) \
65{ return xstrto##W##_range(str, b, l, u); } \
66extern inline \
67narrow xato##N##_range_sfx(const char *str, narrow l, narrow u, const struct suffix_mult *sfx) \
68{ return xato##W##_range_sfx(str, l, u, sfx); } \
69extern inline \
70narrow xato##N##_range(const char *str, narrow l, narrow u) \
71{ return xato##W##_range(str, l, u); } \
72extern inline \
73narrow xato##N##_sfx(const char *str, const struct suffix_mult *sfx) \
74{ return xato##W##_sfx(str, sfx); } \
75extern inline \
76narrow xato##N(const char *str) \
77{ return xato##W(str); } \
78
79/* If long == long long, then just map them one-to-one */
80#if ULONG_MAX == ULLONG_MAX
81DEFINE_EQUIV_STR_CONV(long, l, ll, ul, ull)
82#else
83/* Else provide extern defs */
84DECLARE_STR_CONV(long, l, ul)
85#endif
86
87/* Same for int -> [long] long */
88#if UINT_MAX == ULLONG_MAX
89DEFINE_EQUIV_STR_CONV(int, i, ll, u, ull)
90#elif UINT_MAX == ULONG_MAX
91DEFINE_EQUIV_STR_CONV(int, i, l, u, ul)
92#else
93DECLARE_STR_CONV(int, i, u)
94#endif