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/language_tag.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/language_tag.cc')
| -rw-r--r-- | src/language_tag.cc | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/language_tag.cc b/src/language_tag.cc index 8520a571..532dd557 100644 --- a/src/language_tag.cc +++ b/src/language_tag.cc @@ -40,6 +40,7 @@ #include "compose.hpp" #include "dcp_assert.h" #include "exceptions.h" +#include "file.h" #include "language_tag.h" #include <boost/algorithm/string.hpp> #include <string> @@ -50,8 +51,8 @@ using std::ostream; using std::pair; using std::string; using std::vector; -using boost::optional; using boost::algorithm::trim; +using boost::optional; using namespace dcp; @@ -452,23 +453,22 @@ LanguageTag::get_subtag_description (LanguageTag::SubtagType type, string subtag void load_language_tag_list (boost::filesystem::path tags_directory, string name, std::function<void (std::string, std::string)> add) { - auto f = fopen_boost (tags_directory / name, "r"); + File f(tags_directory / name, "r"); if (!f) { throw FileError ("Could not open tags file", tags_directory / name, errno); } char buffer[512]; int i = 0; - while (!feof(f)) { - char* r = fgets (buffer, sizeof(buffer), f); + while (!f.eof()) { + char* r = f.gets(buffer, sizeof(buffer)); if (r == 0) { break; } string a = buffer; trim (a); - r = fgets (buffer, sizeof(buffer), f); + r = f.gets(buffer, sizeof(buffer)); if (r == 0) { - fclose (f); throw FileError ("Bad tags file", tags_directory / name, -1); } string b = buffer; @@ -476,8 +476,6 @@ load_language_tag_list (boost::filesystem::path tags_directory, string name, std add (a, b); ++i; } - - fclose (f); } |
