Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: userver/universal/src/hostinfo/blocking/get_hostname.cpp
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- diff --git a/userver/universal/src/hostinfo/blocking/get_hostname.cpp b/userver/universal/src/hostinfo/blocking/get_hostname.cpp
- --- a/userver/universal/src/hostinfo/blocking/get_hostname.cpp
- +++ b/userver/universal/src/hostinfo/blocking/get_hostname.cpp
- @@ -20,18 +20,21 @@
- const auto kHostNameMax = MAXHOSTNAMELEN;
- #endif /* HOST_NAME_MAX */
- -} // namespace
- +/*constinit*/ std::array<char, kHostNameMax> host_name{};
- -std::string GetRealHostName() {
- - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init): performance
- - std::array<char, kHostNameMax> host_name;
- +std::string_view DoGetRealHostName() {
- if (::gethostname(host_name.data(), host_name.size()) == -1) {
- const auto code = std::make_error_code(std::errc{errno});
- throw std::system_error(code, "Error while getting hostname");
- }
- -
- - return host_name.data();
- + return std::string_view{host_name.data()};
- }
- +
- +const std::string_view host_name_view = DoGetRealHostName();
- +
- +} // namespace
- +
- +std::string GetRealHostName() { return std::string{host_name_view}; }
- } // namespace hostinfo::blocking
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement