From 3789a75ed6c6aa821872ec3e08a997343767d458 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Thu, 5 Nov 2015 20:37:08 +0100 Subject: [PATCH] base: support ascii_to for uint64_t Issue #1764 --- repos/base/include/util/string.h | 29 +++++++++++++++-------- repos/dde_linux/src/lib/wifi/lxcc_emul.cc | 2 +- repos/os/include/vfs/tar_file_system.h | 2 +- repos/os/src/server/tar_fs/record.h | 2 +- repos/os/src/server/tar_rom/main.cc | 4 ++-- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/repos/base/include/util/string.h b/repos/base/include/util/string.h index 50a0bb72af..31b64c24f2 100644 --- a/repos/base/include/util/string.h +++ b/repos/base/include/util/string.h @@ -276,10 +276,10 @@ namespace Genode { * characters in front of the number. If the number is prefixed with "0x", * a base of 16 is used, otherwise a base of 10. */ - inline size_t ascii_to_unsigned_long(const char *s, unsigned long &result, - unsigned base) + template + inline size_t ascii_to_unsigned(const char *s, T &result, unsigned base) { - unsigned long i = 0, value = 0; + T i = 0, value = 0; if (!*s) return i; @@ -334,10 +334,22 @@ namespace Genode { */ inline size_t ascii_to(const char *s, unsigned long &result) { - return ascii_to_unsigned_long(s, result, 0); + return ascii_to_unsigned(s, result, 0); } + /** + * Read unsigned long long value from string + * + * \return number of consumed characters + */ + inline size_t ascii_to(const char *s, unsigned long long &result) + { + return ascii_to_unsigned(s, result, 0); + } + + + /** * Read unsigned int value from string * @@ -345,10 +357,7 @@ namespace Genode { */ inline size_t ascii_to(const char *s, unsigned int &result) { - unsigned long result_long = 0; - size_t ret = ascii_to_unsigned_long(s, result_long, 0); - result = result_long; - return ret; + return ascii_to_unsigned(s, result, 0); } @@ -369,7 +378,7 @@ namespace Genode { int j = 0; unsigned long value = 0; - j = ascii_to_unsigned_long(s, value, 10); + j = ascii_to_unsigned(s, value, 10); if (!j) return i; @@ -391,7 +400,7 @@ namespace Genode { unsigned long res = 0; /* convert numeric part of string */ - int i = ascii_to_unsigned_long(s, res, 0); + int i = ascii_to_unsigned(s, res, 0); /* handle suffixes */ if (i > 0) diff --git a/repos/dde_linux/src/lib/wifi/lxcc_emul.cc b/repos/dde_linux/src/lib/wifi/lxcc_emul.cc index 71b88baca2..f152610bcf 100644 --- a/repos/dde_linux/src/lib/wifi/lxcc_emul.cc +++ b/repos/dde_linux/src/lib/wifi/lxcc_emul.cc @@ -1034,7 +1034,7 @@ int dev_set_name(struct device *dev, const char *fmt, ...) int strict_strtoul(const char *s, unsigned int base, unsigned long *res) { unsigned long r = -EINVAL; - Genode::ascii_to_unsigned_long(s, r, base); + Genode::ascii_to_unsigned(s, r, base); *res = r; return r; diff --git a/repos/os/include/vfs/tar_file_system.h b/repos/os/include/vfs/tar_file_system.h index 60a60ff119..925d8fee83 100644 --- a/repos/os/include/vfs/tar_file_system.h +++ b/repos/os/include/vfs/tar_file_system.h @@ -69,7 +69,7 @@ class Vfs::Tar_file_system : public File_system strncpy(buf, field, sizeof(buf)); unsigned long value = 0; - Genode::ascii_to_unsigned_long(buf, value, 8); + Genode::ascii_to_unsigned(buf, value, 8); return value; } diff --git a/repos/os/src/server/tar_fs/record.h b/repos/os/src/server/tar_fs/record.h index 4384b70b36..fc2105f192 100644 --- a/repos/os/src/server/tar_fs/record.h +++ b/repos/os/src/server/tar_fs/record.h @@ -47,7 +47,7 @@ namespace File_system { strncpy(buf, field, sizeof(buf)); unsigned long value = 0; - ascii_to_unsigned_long(buf, value, 8); + ascii_to_unsigned(buf, value, 8); return value; } diff --git a/repos/os/src/server/tar_rom/main.cc b/repos/os/src/server/tar_rom/main.cc index a81131037b..61e9468d71 100755 --- a/repos/os/src/server/tar_rom/main.cc +++ b/repos/os/src/server/tar_rom/main.cc @@ -79,8 +79,8 @@ class Rom_session_component : public Genode::Rpc_object while (block_id < block_cnt) { unsigned long file_size = 0; - Genode::ascii_to_unsigned_long(_tar_addr + block_id*_BLOCK_LEN + _FIELD_SIZE_LEN, - file_size, 8); + Genode::ascii_to_unsigned(_tar_addr + block_id*_BLOCK_LEN + + _FIELD_SIZE_LEN, file_size, 8); /* get name of tar record */ char const *record_filename = _tar_addr + block_id*_BLOCK_LEN;