10constexpr size_t kErrorStringBufferSize = 1024;
12static inline void throw_with(
const char *message) {
13 throw std::runtime_error(message);
16template <
class... Args>
17static inline void throw_with(
const char *format, Args... args) {
18 char buffer[kErrorStringBufferSize];
19 ::snprintf(buffer,
sizeof(buffer), format, args...);
20 throw std::runtime_error(buffer);
23static inline void check_rc(
int rc,
const char *message) {
24 if (rc != 0) [[unlikely]] {
25 throw_with(
"%s: %s (rc=%d)", message, ::strerror(rc), rc);
29static inline void check_ptr(
void *ptr,
const char *message) {
30 if (ptr ==
nullptr) [[unlikely]] {
31 throw_with(
"%s: %s (errno=%d)", message, ::strerror(errno), errno);
35static inline void check_errno(
int rc,
const char *message) {
36 if (rc < 0) [[unlikely]] {
37 throw_with(
"%s: %s (errno=%d)", message, ::strerror(errno), errno);
41static inline void check_nerrno(
int nerrno,
const char *message) {
42 if (nerrno < 0) [[unlikely]] {
43 throw_with(
"%s: %s (errno=%d)", message, ::strerror(-nerrno), -nerrno);