浏览代码

Fix compile error with Android NDK

Tatsuhiro Tsujikawa 9 年之前
父节点
当前提交
437d4aa776
共有 2 个文件被更改,包括 10 次插入8 次删除
  1. 4 4
      src/OptionHandlerImpl.cc
  2. 6 4
      src/RequestGroupMan.cc

+ 4 - 4
src/OptionHandlerImpl.cc

@@ -623,10 +623,10 @@ void OptimizeConcurrentDownloadsOptionHandler::parseArg(
     PrefPtr pref = PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA;
     std::string* sptr = &coeff_a;
     for (;;) {
-      try {
-        double dbl = std::stod(*sptr);
-      }
-      catch (std::invalid_argument& ex) {
+      char *end;
+      errno = 0;
+      auto dbl = strtod(sptr->c_str(), &end);
+      if (errno != 0 || sptr->c_str() + sptr->size() != end) {
         throw DL_ABORT_EX(fmt("Bad number '%s'", sptr->c_str()));
       }
       option.put(pref, *sptr);

+ 6 - 4
src/RequestGroupMan.cc

@@ -138,10 +138,12 @@ bool RequestGroupMan::setupOptimizeConcurrentDownloads(void)
       option_->getAsBool(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS);
   if (optimizeConcurrentDownloads_) {
     if (option_->defined(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA)) {
-      optimizeConcurrentDownloadsCoeffA_ =
-          std::stod(option_->get(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA));
-      optimizeConcurrentDownloadsCoeffB_ =
-          std::stod(option_->get(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFB));
+      optimizeConcurrentDownloadsCoeffA_ = strtod(
+          option_->get(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA).c_str(),
+          nullptr);
+      optimizeConcurrentDownloadsCoeffB_ = strtod(
+          option_->get(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFB).c_str(),
+          nullptr);
     }
   }
   return optimizeConcurrentDownloads_;