Boost logo

Boost :

Subject: Re: [boost] [system] A non-allocating message() overload
From: Peter Dimov (lists_at_[hidden])
Date: 2018-09-19 19:53:47

Andrey Semashev wrote:
> > virtual char const* message( int ev, char* buffer, size_t len )
> > noexcept;
> I like the idea, but what about platforms that don't have strerror_r?

All platforms should be able to implement this interface; you could for
instance FormatMessageA into the provided buffer directly, or call strerror
and then copy the string into the buffer, and so on.

> noexcept means that the new overload cannot be implemented atop the
> standard one (e.g. one can't forward the call to the current
> std::error_category::message).

For compatibility reasons (if we make this function pure this will break all
existing user categories) we'll have to provide a default implementation in
terms of the string-returning one (even though the reverse would be more
natural.) It would be something like

        string msg = message(ev);
        strlcpy(buffer, msg.c_str(), len);
        return buffer;
        return "Message unavailable";

Boost list run by bdawes at, gregod at, cpdaniel at, john at