aboutsummaryrefslogtreecommitdiff
path: root/include
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
parent809a6e310443d0b5010c8b293cab0160608c1b02 (diff)
downloadbusybox-ed836cdc30642ddbecc286b279d461ca44135cbb.tar.gz
regularize str -> num convertors
Diffstat (limited to 'include')
-rw-r--r--include/libbb.h35
-rw-r--r--include/xatonum.h94
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 {
const char *suffix;
unsigned mult;
};
-unsigned long long xstrtoull(const char *numstr, int base);
-unsigned long long xatoull(const char *numstr);
-unsigned long xstrtoul_range_sfx(const char *numstr, int base,
- unsigned long lower,
- unsigned long upper,
- const struct suffix_mult *suffixes);
-unsigned long xstrtoul_range(const char *numstr, int base,
- unsigned long lower,
- unsigned long upper);
-unsigned long xstrtoul_sfx(const char *numstr, int base,
- const struct suffix_mult *suffixes);
-unsigned long xstrtoul(const char *numstr, int base);
-unsigned long xatoul_range_sfx(const char *numstr,
- unsigned long lower,
- unsigned long upper,
- const struct suffix_mult *suffixes);
-unsigned long xatoul_sfx(const char *numstr,
- const struct suffix_mult *suffixes);
-unsigned long xatoul_range(const char *numstr,
- unsigned long lower,
- unsigned long upper);
-unsigned long xatoul(const char *numstr);
-long xstrtol_range_sfx(const char *numstr, int base,
- long lower,
- long upper,
- const struct suffix_mult *suffixes);
-long xstrtol_range(const char *numstr, int base, long lower, long upper);
-long xatol_range_sfx(const char *numstr,
- long lower,
- long upper,
- const struct suffix_mult *suffixes);
-long xatol_range(const char *numstr, long lower, long upper);
-long xatol_sfx(const char *numstr, const struct suffix_mult *suffixes);
-long xatol(const char *numstr);
+#include "xatonum.h"
/* Specialized: */
unsigned xatou_range(const char *numstr, unsigned lower, unsigned upper);
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 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * ascii-to-numbers implementations for busybox
+ *
+ * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
+ *
+ * Licensed under GPLv2, see file LICENSE in this tarball for details.
+ */
+
+/* Provides extern declarations of functions */
+#define DECLARE_STR_CONV(type, T, UT) \
+\
+unsigned type xstrto##UT##_range_sfx(const char *str, int b, unsigned type l, unsigned type u, const struct suffix_mult *sfx); \
+unsigned type xstrto##UT##_range(const char *str, int b, unsigned type l, unsigned type u); \
+unsigned type xstrto##UT##_sfx(const char *str, int b, const struct suffix_mult *sfx); \
+unsigned type xstrto##UT(const char *str, int b); \
+unsigned type xato##UT##_range_sfx(const char *str, unsigned type l, unsigned type u, const struct suffix_mult *sfx); \
+unsigned type xato##UT##_range(const char *str, unsigned type l, unsigned type u); \
+unsigned type xato##UT##_sfx(const char *str, const struct suffix_mult *sfx); \
+unsigned type xato##UT(const char *str); \
+type xstrto##T##_range_sfx(const char *str, int b, type l, type u, const struct suffix_mult *sfx) ;\
+type xstrto##T##_range(const char *str, int b, type l, type u); \
+type xato##T##_range_sfx(const char *str, type l, type u, const struct suffix_mult *sfx); \
+type xato##T##_range(const char *str, type l, type u); \
+type xato##T##_sfx(const char *str, const struct suffix_mult *sfx); \
+type xato##T(const char *str); \
+
+/* Unsigned long long functions always exist */
+DECLARE_STR_CONV(long long, ll, ull)
+
+
+/* Provides extern inline definitions of functions */
+/* (useful for mapping them to the type of the same width) */
+#define DEFINE_EQUIV_STR_CONV(narrow, N, W, UN, UW) \
+\
+extern inline \
+unsigned narrow xstrto##UN##_range_sfx(const char *str, int b, unsigned narrow l, unsigned narrow u, const struct suffix_mult *sfx) \
+{ return xstrto##UW##_range_sfx(str, b, l, u, sfx); } \
+extern inline \
+unsigned narrow xstrto##UN##_range(const char *str, int b, unsigned narrow l, unsigned narrow u) \
+{ return xstrto##UW##_range(str, b, l, u); } \
+extern inline \
+unsigned narrow xstrto##UN##_sfx(const char *str, int b, const struct suffix_mult *sfx) \
+{ return xstrto##UW##_sfx(str, b, sfx); } \
+extern inline \
+unsigned narrow xstrto##UN(const char *str, int b) \
+{ return xstrto##UW(str, b); } \
+extern inline \
+unsigned narrow xato##UN##_range_sfx(const char *str, unsigned narrow l, unsigned narrow u, const struct suffix_mult *sfx) \
+{ return xato##UW##_range_sfx(str, l, u, sfx); } \
+extern inline \
+unsigned narrow xato##UN##_range(const char *str, unsigned narrow l, unsigned narrow u) \
+{ return xato##UW##_range(str, l, u); } \
+extern inline \
+unsigned narrow xato##UN##_sfx(const char *str, const struct suffix_mult *sfx) \
+{ return xato##UW##_sfx(str, sfx); } \
+extern inline \
+unsigned narrow xato##UN(const char *str) \
+{ return xato##UW(str); } \
+extern inline \
+narrow xstrto##N##_range_sfx(const char *str, int b, narrow l, narrow u, const struct suffix_mult *sfx) \
+{ return xstrto##W##_range_sfx(str, b, l, u, sfx); } \
+extern inline \
+narrow xstrto##N##_range(const char *str, int b, narrow l, narrow u) \
+{ return xstrto##W##_range(str, b, l, u); } \
+extern inline \
+narrow xato##N##_range_sfx(const char *str, narrow l, narrow u, const struct suffix_mult *sfx) \
+{ return xato##W##_range_sfx(str, l, u, sfx); } \
+extern inline \
+narrow xato##N##_range(const char *str, narrow l, narrow u) \
+{ return xato##W##_range(str, l, u); } \
+extern inline \
+narrow xato##N##_sfx(const char *str, const struct suffix_mult *sfx) \
+{ return xato##W##_sfx(str, sfx); } \
+extern inline \
+narrow xato##N(const char *str) \
+{ return xato##W(str); } \
+
+/* If long == long long, then just map them one-to-one */
+#if ULONG_MAX == ULLONG_MAX
+DEFINE_EQUIV_STR_CONV(long, l, ll, ul, ull)
+#else
+/* Else provide extern defs */
+DECLARE_STR_CONV(long, l, ul)
+#endif
+
+/* Same for int -> [long] long */
+#if UINT_MAX == ULLONG_MAX
+DEFINE_EQUIV_STR_CONV(int, i, ll, u, ull)
+#elif UINT_MAX == ULONG_MAX
+DEFINE_EQUIV_STR_CONV(int, i, l, u, ul)
+#else
+DECLARE_STR_CONV(int, i, u)
+#endif