diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-04-12 22:34:04 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-04-20 20:04:21 +0200 |
| commit | 05bfa3d1fe9e274ed195647c6f74cb272f00c23d (patch) | |
| tree | 1372760463b288ff4e10ef7fb6e7414e202829f5 /src/rating.cc | |
| parent | 0338e7a7c19617f9ebb64ee02fbf3cceab8cf03f (diff) | |
Add and use new File class.master
It was always a bit troubling that fopen_boost wasn't exception safe,
and this also fixes a leak where load_ratings_list would never close
the ratings file.
Diffstat (limited to 'src/rating.cc')
| -rw-r--r-- | src/rating.cc | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/rating.cc b/src/rating.cc index dc32ec9c..21960365 100644 --- a/src/rating.cc +++ b/src/rating.cc @@ -33,6 +33,7 @@ #include "exceptions.h" +#include "file.h" #include "rating.h" #include "util.h" #include <libcxml/cxml.h> @@ -82,14 +83,14 @@ dcp::rating_systems() void dcp::load_rating_list(boost::filesystem::path ratings_file) { - auto f = fopen_boost (ratings_file, "r"); + File f(ratings_file, "r"); if (!f) { throw FileError ("Could not open ratings file", ratings_file, errno); } - auto get_line_no_throw = [f, ratings_file]() -> optional<string> { + auto get_line_no_throw = [&f, ratings_file]() -> optional<string> { char buffer[512]; - char* r = fgets(buffer, sizeof(buffer), f); + char* r = f.gets(buffer, sizeof(buffer)); if (r == 0) { return {}; } @@ -108,7 +109,7 @@ dcp::load_rating_list(boost::filesystem::path ratings_file) optional<string> agency; - while (!feof(f)) { + while (!f.eof()) { if (!agency) { agency = get_line(); } @@ -117,7 +118,7 @@ dcp::load_rating_list(boost::filesystem::path ratings_file) auto country_code = get_line(); RatingSystem system(*agency, name, country_and_region_names, country_code); - while (!feof(f)) { + while (!f.eof()) { auto rating = get_line_no_throw(); if (!rating) { /* End of the file */ |
