move patient_write to share.h because it now has multiple users
[ust.git] / share / usterr.h
CommitLineData
59b161cd
PMF
1#ifndef USTERR_H
2#define USTERR_H
3
d61bfa72 4#include <string.h>
dd80aafe
PMF
5#include <sys/types.h>
6#include <sys/syscall.h>
7#include <errno.h>
d61bfa72 8
2028e7fd
PMF
9#ifndef UST_COMPONENT
10//#error UST_COMPONENT is undefined
11#define UST_COMPONENT libust
12#endif
13
14/* To stringify the expansion of a define */
15#define XSTR(d) STR(d)
16#define STR(s) #s
17
18#define UST_STR_COMPONENT XSTR(UST_COMPONENT)
19
dd80aafe
PMF
20#define ERRMSG(fmt, args...) do { fprintf(stderr, UST_STR_COMPONENT "[%ld/%ld]: " fmt " (" __FILE__ ":" XSTR(__LINE__) ")\n", (long) getpid(), (long) syscall(SYS_gettid), ## args); fflush(stderr); } while(0)
21
2028e7fd 22#define DEBUG
17674885 23#ifdef DEBUG
dd80aafe 24# define DBG(fmt, args...) ERRMSG(fmt, ## args)
17674885
PMF
25#else
26# define DBG(fmt, args...) do {} while(0)
27#endif
dd80aafe
PMF
28#define WARN(fmt, args...) ERRMSG("Warning: " fmt, ## args)
29#define ERR(fmt, args...) ERRMSG("Error: " fmt, ## args)
30#define BUG(fmt, args...) ERRMSG("BUG: " fmt, ## args)
d61bfa72
PMF
31
32#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE)
33#define PERROR(call, args...)\
34 do { \
35 char buf[200] = "Error in strerror_r()"; \
36 strerror_r(errno, buf, sizeof(buf)); \
dd80aafe 37 ERRMSG("Error: " call ": %s", ## args, buf); \
d61bfa72
PMF
38 } while(0);
39#else
40#define PERROR(call, args...)\
41 do { \
42 char *buf; \
43 char tmp[200]; \
44 buf = strerror_r(errno, tmp, sizeof(tmp)); \
dd80aafe 45 ERRMSG("Error: " call ": %s", ## args, buf); \
d61bfa72
PMF
46 } while(0);
47#endif
c9b64079
PMF
48
49#define BUG_ON(condition) do { if (unlikely(condition)) ERR("condition not respected (BUG)"); } while(0)
5f54827b 50#define WARN_ON(condition) do { if (unlikely(condition)) WARN("condition not respected on line %s:%d", __FILE__, __LINE__); } while(0)
c9b64079 51
59b161cd 52#endif /* USTERR_H */
This page took 0.025741 seconds and 4 git commands to generate.