diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-25 14:44:13 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-25 14:44:13 +0000 |
commit | ed836cdc30642ddbecc286b279d461ca44135cbb (patch) | |
tree | 70735d4bd1e34de43aa3f8092446caf460bd2540 /include | |
parent | 809a6e310443d0b5010c8b293cab0160608c1b02 (diff) | |
download | busybox-w32-ed836cdc30642ddbecc286b279d461ca44135cbb.tar.gz busybox-w32-ed836cdc30642ddbecc286b279d461ca44135cbb.tar.bz2 busybox-w32-ed836cdc30642ddbecc286b279d461ca44135cbb.zip |
regularize str -> num convertors
Diffstat (limited to 'include')
-rw-r--r-- | include/libbb.h | 35 | ||||
-rw-r--r-- | include/xatonum.h | 94 |
2 files changed, 95 insertions, 34 deletions
diff --git a/include/libbb.h b/include/libbb.h index 99a1928df..152fb7e01 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -315,40 +315,7 @@ struct suffix_mult { | |||
315 | const char *suffix; | 315 | const char *suffix; |
316 | unsigned mult; | 316 | unsigned mult; |
317 | }; | 317 | }; |
318 | unsigned long long xstrtoull(const char *numstr, int base); | 318 | #include "xatonum.h" |
319 | unsigned long long xatoull(const char *numstr); | ||
320 | unsigned long xstrtoul_range_sfx(const char *numstr, int base, | ||
321 | unsigned long lower, | ||
322 | unsigned long upper, | ||
323 | const struct suffix_mult *suffixes); | ||
324 | unsigned long xstrtoul_range(const char *numstr, int base, | ||
325 | unsigned long lower, | ||
326 | unsigned long upper); | ||
327 | unsigned long xstrtoul_sfx(const char *numstr, int base, | ||
328 | const struct suffix_mult *suffixes); | ||
329 | unsigned long xstrtoul(const char *numstr, int base); | ||
330 | unsigned long xatoul_range_sfx(const char *numstr, | ||
331 | unsigned long lower, | ||
332 | unsigned long upper, | ||
333 | const struct suffix_mult *suffixes); | ||
334 | unsigned long xatoul_sfx(const char *numstr, | ||
335 | const struct suffix_mult *suffixes); | ||
336 | unsigned long xatoul_range(const char *numstr, | ||
337 | unsigned long lower, | ||
338 | unsigned long upper); | ||
339 | unsigned long xatoul(const char *numstr); | ||
340 | long xstrtol_range_sfx(const char *numstr, int base, | ||
341 | long lower, | ||
342 | long upper, | ||
343 | const struct suffix_mult *suffixes); | ||
344 | long xstrtol_range(const char *numstr, int base, long lower, long upper); | ||
345 | long xatol_range_sfx(const char *numstr, | ||
346 | long lower, | ||
347 | long upper, | ||
348 | const struct suffix_mult *suffixes); | ||
349 | long xatol_range(const char *numstr, long lower, long upper); | ||
350 | long xatol_sfx(const char *numstr, const struct suffix_mult *suffixes); | ||
351 | long xatol(const char *numstr); | ||
352 | /* Specialized: */ | 319 | /* Specialized: */ |
353 | unsigned xatou_range(const char *numstr, unsigned lower, unsigned upper); | 320 | unsigned xatou_range(const char *numstr, unsigned lower, unsigned upper); |
354 | unsigned xatou_sfx(const char *numstr, const struct suffix_mult *suffixes); | 321 | unsigned xatou_sfx(const char *numstr, const struct suffix_mult *suffixes); |
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 | \ | ||
13 | unsigned type xstrto##UT##_range_sfx(const char *str, int b, unsigned type l, unsigned type u, const struct suffix_mult *sfx); \ | ||
14 | unsigned type xstrto##UT##_range(const char *str, int b, unsigned type l, unsigned type u); \ | ||
15 | unsigned type xstrto##UT##_sfx(const char *str, int b, const struct suffix_mult *sfx); \ | ||
16 | unsigned type xstrto##UT(const char *str, int b); \ | ||
17 | unsigned type xato##UT##_range_sfx(const char *str, unsigned type l, unsigned type u, const struct suffix_mult *sfx); \ | ||
18 | unsigned type xato##UT##_range(const char *str, unsigned type l, unsigned type u); \ | ||
19 | unsigned type xato##UT##_sfx(const char *str, const struct suffix_mult *sfx); \ | ||
20 | unsigned type xato##UT(const char *str); \ | ||
21 | type xstrto##T##_range_sfx(const char *str, int b, type l, type u, const struct suffix_mult *sfx) ;\ | ||
22 | type xstrto##T##_range(const char *str, int b, type l, type u); \ | ||
23 | type xato##T##_range_sfx(const char *str, type l, type u, const struct suffix_mult *sfx); \ | ||
24 | type xato##T##_range(const char *str, type l, type u); \ | ||
25 | type xato##T##_sfx(const char *str, const struct suffix_mult *sfx); \ | ||
26 | type xato##T(const char *str); \ | ||
27 | |||
28 | /* Unsigned long long functions always exist */ | ||
29 | DECLARE_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 | \ | ||
36 | extern inline \ | ||
37 | unsigned 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); } \ | ||
39 | extern inline \ | ||
40 | unsigned narrow xstrto##UN##_range(const char *str, int b, unsigned narrow l, unsigned narrow u) \ | ||
41 | { return xstrto##UW##_range(str, b, l, u); } \ | ||
42 | extern inline \ | ||
43 | unsigned narrow xstrto##UN##_sfx(const char *str, int b, const struct suffix_mult *sfx) \ | ||
44 | { return xstrto##UW##_sfx(str, b, sfx); } \ | ||
45 | extern inline \ | ||
46 | unsigned narrow xstrto##UN(const char *str, int b) \ | ||
47 | { return xstrto##UW(str, b); } \ | ||
48 | extern inline \ | ||
49 | unsigned 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); } \ | ||
51 | extern inline \ | ||
52 | unsigned narrow xato##UN##_range(const char *str, unsigned narrow l, unsigned narrow u) \ | ||
53 | { return xato##UW##_range(str, l, u); } \ | ||
54 | extern inline \ | ||
55 | unsigned narrow xato##UN##_sfx(const char *str, const struct suffix_mult *sfx) \ | ||
56 | { return xato##UW##_sfx(str, sfx); } \ | ||
57 | extern inline \ | ||
58 | unsigned narrow xato##UN(const char *str) \ | ||
59 | { return xato##UW(str); } \ | ||
60 | extern inline \ | ||
61 | narrow 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); } \ | ||
63 | extern inline \ | ||
64 | narrow xstrto##N##_range(const char *str, int b, narrow l, narrow u) \ | ||
65 | { return xstrto##W##_range(str, b, l, u); } \ | ||
66 | extern inline \ | ||
67 | narrow 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); } \ | ||
69 | extern inline \ | ||
70 | narrow xato##N##_range(const char *str, narrow l, narrow u) \ | ||
71 | { return xato##W##_range(str, l, u); } \ | ||
72 | extern inline \ | ||
73 | narrow xato##N##_sfx(const char *str, const struct suffix_mult *sfx) \ | ||
74 | { return xato##W##_sfx(str, sfx); } \ | ||
75 | extern inline \ | ||
76 | narrow 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 | ||
81 | DEFINE_EQUIV_STR_CONV(long, l, ll, ul, ull) | ||
82 | #else | ||
83 | /* Else provide extern defs */ | ||
84 | DECLARE_STR_CONV(long, l, ul) | ||
85 | #endif | ||
86 | |||
87 | /* Same for int -> [long] long */ | ||
88 | #if UINT_MAX == ULLONG_MAX | ||
89 | DEFINE_EQUIV_STR_CONV(int, i, ll, u, ull) | ||
90 | #elif UINT_MAX == ULONG_MAX | ||
91 | DEFINE_EQUIV_STR_CONV(int, i, l, u, ul) | ||
92 | #else | ||
93 | DECLARE_STR_CONV(int, i, u) | ||
94 | #endif | ||