From 62dc2f468faf5adb2b21e45b43b2f0ba6fab0f66 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 5 Sep 2016 21:57:53 +0200 Subject: [PATCH] added Utilities::cwd --- src/uvw/util.hpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/uvw/util.hpp b/src/uvw/util.hpp index d0449967..ec9d4ff1 100644 --- a/src/uvw/util.hpp +++ b/src/uvw/util.hpp @@ -232,6 +232,9 @@ struct InterfaceAddress { namespace details { +static constexpr std::size_t DEFAULT_SIZE = 128; + + template struct IpTraits; @@ -258,12 +261,12 @@ struct IpTraits { }; -template +template Addr address(const typename details::IpTraits::Type *aptr) noexcept { Addr addr; - char name[N]; + char name[DEFAULT_SIZE]; - int err = details::IpTraits::nameFunc(aptr, name, N); + int err = details::IpTraits::nameFunc(aptr, name, DEFAULT_SIZE); if(0 == err) { addr.port = ntohs(details::IpTraits::sinPort(aptr)); @@ -291,16 +294,16 @@ Addr address(F &&f, const H *handle) noexcept { } -template -std::string path(F &&f, H *handle) noexcept { - std::size_t size = N; +template +std::string path(F &&f, Args... args) noexcept { + std::size_t size = DEFAULT_SIZE; char buf[size]; std::string str{}; - auto err = std::forward(f)(handle, buf, &size); + auto err = std::forward(f)(args..., buf, &size); if(UV_ENOBUFS == err) { std::unique_ptr data{new char[size]}; - err = std::forward(f)(handle, data.get(), &size); + err = std::forward(f)(args..., data.get(), &size); if(0 == err) { str = data.get(); @@ -533,6 +536,14 @@ struct Utilities { return uv_hrtime(); } + /** + * @brief Gets the current working directory. + * @return The current working directory. + */ + static std::string cwd() noexcept { + return details::path(&uv_cwd); + } + /** * @brief Changes the current working directory. * @param dir The working directory to be set. @@ -549,7 +560,6 @@ struct Utilities { * * * uv_getrusage * * uv_exepath - * * uv_cwd * * uv_os_homedir * * uv_os_tmpdir * * uv_os_get_passwd