Skip to content

Commit

Permalink
Search for '/' after "zoneinfo" in current_zone()
Browse files Browse the repository at this point in the history
  • Loading branch information
HowardHinnant committed Oct 14, 2019
1 parent 23fa1bb commit 3f0f9b3
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/tz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3697,20 +3697,22 @@ tzdb::current_zone() const
throw system_error(errno, system_category(), "realpath() failed");
#if HAS_STRING_VIEW
string_view result = rp;
CONSTDATA string_view zoneinfo = "/zoneinfo/";
const size_t pos = result.rfind(zoneinfo);
CONSTDATA string_view zoneinfo = "zoneinfo";
size_t pos = result.rfind(zoneinfo);
if (pos == result.npos)
throw runtime_error(
"current_zone() failed to find \"/zoneinfo/\" in " + string(result));
result.remove_prefix(pos + zoneinfo.size());
"current_zone() failed to find \"zoneinfo\" in " + string(result));
pos = result.find('/', pos);
result.remove_prefix(pos + 1);
#else
string result = rp;
CONSTDATA char zoneinfo[] = "/zoneinfo/";
const size_t pos = result.rfind(zoneinfo);
CONSTDATA char zoneinfo[] = "zoneinfo";
size_t pos = result.rfind(zoneinfo);
if (pos == result.npos)
throw runtime_error(
"current_zone() failed to find \"/zoneinfo/\" in " + result);
result.erase(0, pos + sizeof(zoneinfo) - 1);
"current_zone() failed to find \"zoneinfo\" in " + result);
pos = result.find('/', pos);
result.erase(0, pos + 1);
#endif
return locate_zone(result);
}
Expand Down

0 comments on commit 3f0f9b3

Please sign in to comment.