Ensure logging doesn't affect errno

This commit is contained in:
Matthew Parkinson
2022-05-08 20:32:52 +01:00
committed by Matthew Parkinson
parent 14b7b40a82
commit 9f9964239e

View File

@@ -163,6 +163,9 @@ namespace snmalloc
*/
static void message(const char* const str) noexcept
{
// We don't want logging to affect the errno behaviour of the program.
auto hold = KeepErrno();
void* nl = const_cast<char*>("\n");
struct iovec iov[] = {{const_cast<char*>(str), strlen(str)}, {nl, 1}};
UNUSED(writev(STDERR_FILENO, iov, sizeof(iov) / sizeof(struct iovec)));