Commit ec6ecd4e authored by Kirill Smelkov's avatar Kirill Smelkov

lib/bug: BUGerr(err) - like BUGe() but takes error code explicitly

We'll need this for function which return error not in errno - e.g.
pthread_sigmask().
parent 8213a9e8
...@@ -36,6 +36,10 @@ ...@@ -36,6 +36,10 @@
__bug(__FILE__, __LINE__, __func__); \ __bug(__FILE__, __LINE__, __func__); \
} while (0) } while (0)
#define BUGerr(err) do { \
__bug_err(__FILE__, __LINE__, __func__, err); \
} while (0)
#define BUGe() do { \ #define BUGe() do { \
__bug_errno(__FILE__, __LINE__, __func__); \ __bug_errno(__FILE__, __LINE__, __func__); \
} while (0) } while (0)
...@@ -57,6 +61,8 @@ void __todo(const char *, const char *, unsigned, const char *) ...@@ -57,6 +61,8 @@ void __todo(const char *, const char *, unsigned, const char *)
void __warn(const char *, unsigned, const char *, const char *); void __warn(const char *, unsigned, const char *, const char *);
void __bug(const char *, unsigned, const char *) void __bug(const char *, unsigned, const char *)
__attribute__((noreturn)); __attribute__((noreturn));
void __bug_err(const char *, unsigned, const char *, int)
__attribute__((noreturn));
void __bug_errno(const char *, unsigned, const char *) void __bug_errno(const char *, unsigned, const char *)
__attribute__((noreturn)); __attribute__((noreturn));
void __bug_fail(const char *, const char *, unsigned, const char *) void __bug_fail(const char *, const char *, unsigned, const char *)
......
...@@ -43,17 +43,23 @@ void __bug(const char *file, unsigned line, const char *func) ...@@ -43,17 +43,23 @@ void __bug(const char *file, unsigned line, const char *func)
} }
void __bug_errno(const char *file, unsigned line, const char *func) void __bug_err(const char *file, unsigned line, const char *func, int err)
{ {
char errno_buf[128]; char err_buf[128];
char *errno_str; char *err_str;
errno_str = strerror_r(errno, errno_buf, sizeof(errno_buf)); err_str = strerror_r(err, err_buf, sizeof(err_buf));
fprintf(stderr, "%s:%u %s\tBUG! (%s)\n", file, line, func, errno_str); fprintf(stderr, "%s:%u %s\tBUG! (%s)\n", file, line, func, err_str);
abort(); abort();
} }
void __bug_errno(const char *file, unsigned line, const char *func)
{
__bug_err(file, line, func, errno);
}
void __warn(const char *file, unsigned line, const char *func, const char *msg) void __warn(const char *file, unsigned line, const char *func, const char *msg)
{ {
fprintf(stderr, "%s:%u %s WARN: %s\n", file, line, func, msg); fprintf(stderr, "%s:%u %s WARN: %s\n", file, line, func, msg);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment