-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherr.h
More file actions
40 lines (31 loc) · 2.05 KB
/
err.h
File metadata and controls
40 lines (31 loc) · 2.05 KB
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
36
37
38
39
40
#ifndef MIM_ERR_H
#define MIM_ERR_H
#include <stdnoreturn.h>
/* Assert that expression evaluates to zero (otherwise use result as error number, as in pthreads). */
#define ASSERT_ZERO(expr) \
do { \
int errno = (expr); \
if (errno != 0) \
syserr( \
"Failed: %s\n\tIn function %s() in %s line %d.\n\tErrno: ", \
#expr, __func__, __FILE__, __LINE__ \
); \
} while(0)
/*
Assert that expression doesn't evaluate to -1 (as almost every system function does in case of error).
Use as a function, with a semicolon, like: ASSERT_SYS_OK(close(fd));
(This is implemented with a 'do { ... } while(0)' block so that it can be used between if () and else.)
*/
#define ASSERT_SYS_OK(expr) \
do { \
if ((expr) == -1) \
syserr( \
"System command failed: %s\n\tIn function %s() in %s line %d.\n\tErrno: ", \
#expr, __func__, __FILE__, __LINE__ \
); \
} while(0)
/* Prints with information about system error (errno) and quits. */
_Noreturn extern void syserr(const char* fmt, ...);
/* Prints (like printf) and quits. */
_Noreturn extern void fatal(const char* fmt, ...);
#endif