Skip to content

Commit

Permalink
mx_util: Add mx_assert_return_*()
Browse files Browse the repository at this point in the history
  • Loading branch information
mariux committed May 13, 2015
1 parent 35a9ef6 commit a602784
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions mx_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@
#include <stdint.h>
#include <stdarg.h>

#include "mx_log.h"

#ifdef MX_NDEBUG
# include <assert.h>
# define mx_assert_return_minus_errno(test, eno) \
assert(test)
# define mx_assert_return_NULL(test, eno) \
assert(test)
#else
# define mx_assert_return_minus_errno(test, eno) \
do {\
if (!(test)) {\
errno=(eno);\
mx_log_debug("Assertion '" #test "' failed. Returning -(errno=" #eno ") [%d]: %m", -errno);\
return -errno;\
}\
} while (0)

# define mx_assert_return_NULL(test, eno) \
do {\
if (!(test)) {\
errno=(eno);\
mx_log_debug("Assertion '" #test "' failed. Setting errno=" #eno " [%d] and returning NULL: %m", errno);\
return NULL;\
}\
} while (0)
#endif

#undef mx_free_null
#define mx_free_null(a) do { free(a); (a) = NULL; } while(0)

Expand Down

0 comments on commit a602784

Please sign in to comment.