From: Arnaud Giersch Date: Wed, 29 Apr 2020 12:18:54 +0000 (+0200) Subject: Also check that the i/o operation didn't fail. X-Git-Tag: v3.26~639 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/170f768cfb3e06f5d870854928bc04cfcddcef52 Also check that the i/o operation didn't fail. --- diff --git a/src/xbt/random.cpp b/src/xbt/random.cpp index 539340bb67..5621f5a345 100644 --- a/src/xbt/random.cpp +++ b/src/xbt/random.cpp @@ -22,25 +22,21 @@ namespace random { bool Random::read_state(std::string filename) { std::ifstream file(filename); - if (file) { - file >> mt19937_gen; - return true; - } else { - XBT_WARN("Could not open %s and thus not save the RNG state.", filename.c_str()); - return false; - } + file >> mt19937_gen; + file.close(); + if (file.fail()) + XBT_WARN("Could not save the RNG state to file %s.", filename.c_str()); + return not file.fail(); } bool Random::write_state(std::string filename) { std::ofstream file(filename); - if (file) { - file << mt19937_gen; - return true; - } else { - XBT_WARN("Could not open %s and thus not read the RNG state.", filename.c_str()); - return false; - } + file << mt19937_gen; + file.close(); + if (file.fail()) + XBT_WARN("Could not read the RNG state from file %s.", filename.c_str()); + return not file.fail(); } int StdRandom::uniform_int(int min, int max)