diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-08-31 00:18:55 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-08-31 00:18:55 -0400 |
commit | 00b37f071d2c96612892340f5f883b869033d6a1 (patch) | |
tree | 35d484780d5ca53aae43a5a90e9d032c6b1c08a5 /src/common | |
parent | 0bb59f1c38eef467a353faf1a30cf93b64209a27 (diff) | |
download | tor-00b37f071d2c96612892340f5f883b869033d6a1.tar.gz tor-00b37f071d2c96612892340f5f883b869033d6a1.zip |
Revise parsing of time and memory units to handle spaces.
When we added support for fractional units (like 1.5 MB) I broke
support for giving units with no space (like 2MB). This patch should
fix that. It also adds a propoer tor_parse_double().
Fix for bug 1076. Bugfix on 0.2.2.1-alpha.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/util.c | 11 | ||||
-rw-r--r-- | src/common/util.h | 2 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c index 234180c4d4..19839e23a1 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -735,6 +735,17 @@ tor_parse_ulong(const char *s, int base, unsigned long min, CHECK_STRTOX_RESULT(); } +/** As tor_parse_long(), but return a double. */ +double +tor_parse_double(const char *s, double min, double max, int *ok, char **next) +{ + char *endptr; + double r; + + r = strtod(s, &endptr); + CHECK_STRTOX_RESULT(); +} + /** As tor_parse_log, but return a unit64_t. Only base 10 is guaranteed to * work for now. */ uint64_t diff --git a/src/common/util.h b/src/common/util.h index c7741a64ac..bb384a2a33 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -182,6 +182,8 @@ long tor_parse_long(const char *s, int base, long min, long max, int *ok, char **next); unsigned long tor_parse_ulong(const char *s, int base, unsigned long min, unsigned long max, int *ok, char **next); +double tor_parse_double(const char *s, double min, double max, int *ok, + char **next); uint64_t tor_parse_uint64(const char *s, int base, uint64_t min, uint64_t max, int *ok, char **next); const char *hex_str(const char *from, size_t fromlen) ATTR_NONNULL((1)); |