diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-27 14:43:21 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-27 14:43:21 +0000 |
commit | d686a045c8134d3a42fa5cc6b2e09118e08d603f (patch) | |
tree | 38f509fc9556f68f758c77b06b480cc33b2725eb /include | |
parent | 8a0a83d503a7971895254efa9e79cf15ba1850d4 (diff) | |
download | busybox-w32-d686a045c8134d3a42fa5cc6b2e09118e08d603f.tar.gz busybox-w32-d686a045c8134d3a42fa5cc6b2e09118e08d603f.tar.bz2 busybox-w32-d686a045c8134d3a42fa5cc6b2e09118e08d603f.zip |
safe_strtoXX interface proved to be a bit unconvenient.
Remove it, introduce saner bb_strtoXX.
Saved ~350 bytes.
Diffstat (limited to 'include')
-rw-r--r-- | include/libbb.h | 33 | ||||
-rw-r--r-- | include/xatonum.h | 51 |
2 files changed, 62 insertions, 22 deletions
diff --git a/include/libbb.h b/include/libbb.h index e93031231..63748c85d 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -85,30 +85,31 @@ | |||
85 | /* CONFIG_LFS is on */ | 85 | /* CONFIG_LFS is on */ |
86 | # if ULONG_MAX > 0xffffffff | 86 | # if ULONG_MAX > 0xffffffff |
87 | /* "long" is long enough on this system */ | 87 | /* "long" is long enough on this system */ |
88 | # define STRTOOFF strtol | 88 | # define XSTRTOOFF xstrtoul |
89 | # define SAFE_STRTOOFF safe_strtol | 89 | /* usage: sz = BB_STRTOOFF(s, NULL, 10); if (errno || sz < 0) die(); */ |
90 | # define XSTRTOUOFF xstrtoul | 90 | # define BB_STRTOOFF bb_strtoul |
91 | # define STRTOOFF strtoul | ||
91 | /* usage: printf("size: %"OFF_FMT"d (%"OFF_FMT"x)\n", sz, sz); */ | 92 | /* usage: printf("size: %"OFF_FMT"d (%"OFF_FMT"x)\n", sz, sz); */ |
92 | # define OFF_FMT "l" | 93 | # define OFF_FMT "l" |
93 | # else | 94 | # else |
94 | /* "long" is too short, need "long long" */ | 95 | /* "long" is too short, need "long long" */ |
95 | # define STRTOOFF strtoll | 96 | # define XSTRTOOFF xstrtoull |
96 | # define SAFE_STRTOOFF safe_strtoll | 97 | # define BB_STRTOOFF bb_strtoull |
97 | # define XSTRTOUOFF xstrtoull | 98 | # define STRTOOFF strtoull |
98 | # define OFF_FMT "ll" | 99 | # define OFF_FMT "ll" |
99 | # endif | 100 | # endif |
100 | #else | 101 | #else |
101 | # if 0 /* #if UINT_MAX == 0xffffffff */ | 102 | # if 0 /* #if UINT_MAX == 0xffffffff */ |
102 | /* Doesn't work. off_t is a long. gcc will throw warnings on printf("%d", off_t) | 103 | /* Doesn't work. off_t is a long. gcc will throw warnings on printf("%d", off_t) |
103 | * even if long==int on this arch. Crap... */ | 104 | * even if long==int on this arch. Crap... */ |
105 | # define XSTRTOOFF xstrtou | ||
106 | # define BB_STRTOOFF bb_strtoi | ||
104 | # define STRTOOFF strtol | 107 | # define STRTOOFF strtol |
105 | # define SAFE_STRTOOFF safe_strtoi | ||
106 | # define XSTRTOUOFF xstrtou | ||
107 | # define OFF_FMT "" | 108 | # define OFF_FMT "" |
108 | # else | 109 | # else |
110 | # define XSTRTOOFF xstrtoul | ||
111 | # define BB_STRTOOFF bb_strtol | ||
109 | # define STRTOOFF strtol | 112 | # define STRTOOFF strtol |
110 | # define SAFE_STRTOOFF safe_strtol | ||
111 | # define XSTRTOUOFF xstrtoul | ||
112 | # define OFF_FMT "l" | 113 | # define OFF_FMT "l" |
113 | # endif | 114 | # endif |
114 | #endif | 115 | #endif |
@@ -299,18 +300,6 @@ extern char *utoa(unsigned n); | |||
299 | extern void itoa_to_buf(int n, char *buf, unsigned buflen); | 300 | extern void itoa_to_buf(int n, char *buf, unsigned buflen); |
300 | extern char *itoa(int n); | 301 | extern char *itoa(int n); |
301 | 302 | ||
302 | // FIXME: the prototype doesn't match libc strtoXX -> confusion | ||
303 | // FIXME: alot of unchecked strtoXXX are still in tree | ||
304 | // FIXME: atoi_or_else(str, N)? | ||
305 | extern int safe_strtoi(const char *arg, int* value); | ||
306 | extern int safe_strtou(const char *arg, unsigned* value); | ||
307 | extern int safe_strtod(const char *arg, double* value); | ||
308 | extern int safe_strtol(const char *arg, long* value); | ||
309 | extern int safe_strtoll(const char *arg, long long* value); | ||
310 | extern int safe_strtoul(const char *arg, unsigned long* value); | ||
311 | extern int safe_strtoull(const char *arg, unsigned long long* value); | ||
312 | extern int safe_strtou32(const char *arg, uint32_t* value); | ||
313 | |||
314 | struct suffix_mult { | 303 | struct suffix_mult { |
315 | const char *suffix; | 304 | const char *suffix; |
316 | unsigned mult; | 305 | unsigned mult; |
diff --git a/include/xatonum.h b/include/xatonum.h index 46e49b0eb..585d84623 100644 --- a/include/xatonum.h +++ b/include/xatonum.h | |||
@@ -104,3 +104,54 @@ extern inline uint32_t xatou32(const char *numstr) | |||
104 | return xatoul(numstr); | 104 | return xatoul(numstr); |
105 | return BUG_xatou32_unimplemented(); | 105 | return BUG_xatou32_unimplemented(); |
106 | } | 106 | } |
107 | |||
108 | /* Non-aborting kind of convertors */ | ||
109 | |||
110 | unsigned long long bb_strtoull(const char *arg, char **endp, int base); | ||
111 | long long bb_strtoll(const char *arg, char **endp, int base); | ||
112 | |||
113 | #if ULONG_MAX == ULLONG_MAX | ||
114 | extern inline | ||
115 | unsigned long bb_strtoul(const char *arg, char **endp, int base) | ||
116 | { return bb_strtoull(arg, endp, base); } | ||
117 | extern inline | ||
118 | unsigned long bb_strtol(const char *arg, char **endp, int base) | ||
119 | { return bb_strtoll(arg, endp, base); } | ||
120 | #else | ||
121 | unsigned long bb_strtoul(const char *arg, char **endp, int base); | ||
122 | long bb_strtol(const char *arg, char **endp, int base); | ||
123 | #endif | ||
124 | |||
125 | #if UINT_MAX == ULLONG_MAX | ||
126 | extern inline | ||
127 | unsigned long bb_strtou(const char *arg, char **endp, int base) | ||
128 | { return bb_strtoull(arg, endp, base); } | ||
129 | extern inline | ||
130 | unsigned long bb_strtoi(const char *arg, char **endp, int base) | ||
131 | { return bb_strtoll(arg, endp, base); } | ||
132 | #elif UINT_MAX == ULONG_MAX | ||
133 | extern inline | ||
134 | unsigned long bb_strtou(const char *arg, char **endp, int base) | ||
135 | { return bb_strtoul(arg, endp, base); } | ||
136 | extern inline | ||
137 | unsigned long bb_strtoi(const char *arg, char **endp, int base) | ||
138 | { return bb_strtol(arg, endp, base); } | ||
139 | #else | ||
140 | unsigned long bb_strtou(const char *arg, char **endp, int base); | ||
141 | long bb_strtoi(const char *arg, char **endp, int base); | ||
142 | #endif | ||
143 | |||
144 | int BUG_bb_strtou32_unimplemented(void); | ||
145 | extern inline | ||
146 | uint32_t bb_strtou32(const char *arg, char **endp, int base) | ||
147 | { | ||
148 | if (sizeof(uint32_t) == sizeof(unsigned)) | ||
149 | return bb_strtou(arg, endp, base); | ||
150 | if (sizeof(uint32_t) == sizeof(unsigned long)) | ||
151 | return bb_strtoul(arg, endp, base); | ||
152 | return BUG_bb_strtou32_unimplemented(); | ||
153 | } | ||
154 | |||
155 | /* Floating point */ | ||
156 | |||
157 | /* double bb_strtod(const char *arg, char **endp); */ | ||