util: refine try_read

This commit is contained in:
Michele Caini 2024-10-22 09:25:15 +02:00
parent a4657c479d
commit b53cd6fd8b

View File

@ -250,14 +250,14 @@ namespace details {
static constexpr std::size_t DEFAULT_SIZE = 128; static constexpr std::size_t DEFAULT_SIZE = 128;
template<typename F, typename... Args> template<typename F, typename... Args>
std::string try_read(F &&f, Args &&...args) noexcept { std::string try_read(F &&f, Args &&...args) {
std::size_t size = DEFAULT_SIZE; std::size_t size = DEFAULT_SIZE;
char buf[DEFAULT_SIZE]; char buf[DEFAULT_SIZE];
std::string str{}; std::string str{};
auto err = std::forward<F>(f)(args..., buf, &size); auto err = std::forward<F>(f)(args..., buf, &size);
if(UV_ENOBUFS == err) { if(UV_ENOBUFS == err) {
std::unique_ptr<char[]> data{new char[size]}; auto data = std::make_unique<char[]>(size);
err = std::forward<F>(f)(args..., data.get(), &size); err = std::forward<F>(f)(args..., data.get(), &size);
if(0 == err) { if(0 == err) {
@ -424,7 +424,7 @@ struct utilities {
* *
* @return The accessible subset of the password file entry. * @return The accessible subset of the password file entry.
*/ */
static passwd_info passwd() noexcept; static passwd_info passwd();
/** /**
* @brief Retrieves the scheduling priority of a process. * @brief Retrieves the scheduling priority of a process.