aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.util/save_errno.ccm
blob: 27567f8f8ccf9d888cf26b3353268cef6ee6c056 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// This source code is released into the public domain.
module;

#include <cerrno>

export module nihil.util:save_errno;

// save_errno: save the current value of errno and restore it when we're destroyed.
// this allows wrappers around C functions that use errno to preserve the caller's
// errno value.

namespace nihil {

export struct save_errno final
{
	save_errno() : m_errno(errno) {}

	~save_errno()
	{
		errno = m_errno;
	}

	// Not copyable
	save_errno(const save_errno&) = delete;
	auto operator=(const save_errno&) -> save_errno & = delete;

	// Not movable
	save_errno(save_errno&&) = delete;
	auto operator=(save_errno&&) -> save_errno & = delete;

private:
	int	m_errno;
};

} // namespace nihil