about summary refs log tree commit diff
path: root/src/nix-store/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix-store/main.cc')
-rw-r--r--src/nix-store/main.cc14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/nix-store/main.cc b/src/nix-store/main.cc
index a8acd30c77b7..febe65e5c45e 100644
--- a/src/nix-store/main.cc
+++ b/src/nix-store/main.cc
@@ -1,5 +1,4 @@
 #include <iostream>
-#include <sstream>
 
 #include "globals.hh"
 #include "normalise.hh"
@@ -171,10 +170,8 @@ static void opSubstitute(Strings opFlags, Strings opArgs)
         getline(cin, sub.program);
         string s;
         getline(cin, s);
-        istringstream st(s);
         int n;
-        st >> n;
-        if (!st) throw Error("number expected");
+        if (!string2Int(s, n)) throw Error("number expected");
         while (n--) {
             getline(cin, s);
             sub.args.push_back(s);
@@ -224,11 +221,10 @@ static void opGC(Strings opFlags, Strings opArgs)
         else if (*i == "--print-dead") subOp = soPrintDead;
         else if (*i == "--delete") subOp = soDelete;
         else if (*i == "--min-age") {
-            if (opArgs.size() == 0)
-                throw UsageError("`--min-age' requires an argument");
-            istringstream st(opArgs.front());
-            st >> minAge;
-            if (!st) throw Error("number expected");
+            int n;
+            if (opArgs.size() == 0 || !string2Int(opArgs.front(), n))
+                throw UsageError("`--min-age' requires an integer argument");
+            minAge = n;
         }
         else throw UsageError(format("bad sub-operation `%1%' in GC") % *i);