]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add pdns_stou
authorAki Tuomi <cmouse@desteem.org>
Sat, 12 Dec 2015 08:03:24 +0000 (10:03 +0200)
committerAki Tuomi <cmouse@desteem.org>
Mon, 21 Dec 2015 12:52:00 +0000 (14:52 +0200)
pdns/misc.cc
pdns/misc.hh

index c6a18ebad2f7b2878ba0c2effa6455dcb6aabf61..a7b18c90e2fe1ac6f9c8126b9676ddd86b168b33 100644 (file)
@@ -1236,7 +1236,6 @@ double DiffTime(const struct timeval& first, const struct timeval& second)
   return seconds + useconds/1000000.0;
 }
 
-
 uid_t strToUID(const string &str)
 {
   uid_t result = 0;
@@ -1285,3 +1284,13 @@ gid_t strToGID(const string &str)
   return result;
 }
 
+unsigned int pdns_stou(const std::string& str, size_t * idx, int base);
+{
+  if (str.empty()) return 0; // compability
+  unsigned long result = std::stoul(str, idx, base);
+  if (result > std::numeric_limits<unsigned int>::max()) {
+    throw std::out_of_range("stou");
+  }
+  return static_cast<unsigned int>(result);
+}
+
index 18e1dc2eef30984b093059e2f9c534144dd19f91..14b887b9506168b56e0b55bcf1332093ef15a98c 100644 (file)
@@ -658,3 +658,5 @@ double DiffTime(const struct timespec& first, const struct timespec& second);
 double DiffTime(const struct timeval& first, const struct timeval& second);
 uid_t strToUID(const string &str);
 gid_t strToGID(const string &str);
+
+unsigned int pdns_stou(const std::string& str, size_t * idx = 0, int base = 10);