2014-12-11 10:50:15 +03:00
|
|
|
// Copyright (c) 2012-2014 Konstantin Isakov <ikm@zbackup.org> and ZBackup contributors, see CONTRIBUTORS
|
2014-10-10 13:50:55 +04:00
|
|
|
// Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE
|
2013-07-18 21:33:25 +04:00
|
|
|
|
2015-01-25 19:44:15 +03:00
|
|
|
#ifndef CHECK_HH_INCLUDED
|
|
|
|
#define CHECK_HH_INCLUDED
|
2013-07-18 21:33:25 +04:00
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
// Run-time assertion macro
|
|
|
|
|
|
|
|
// Usage: CHECK( value == 16, "Value is not 16: %d", value );
|
|
|
|
// This will abort() if the value is not 16 with the message stating so.
|
|
|
|
|
|
|
|
// TODO: show the backtrace here, without using __FILE__ __LINE__
|
|
|
|
|
|
|
|
#define CHECK( condition, message, ... ) ({if (!(condition)) \
|
|
|
|
{ \
|
|
|
|
fprintf( stderr, "Check failed: " ); \
|
|
|
|
fprintf( stderr, message, ##__VA_ARGS__ ); \
|
|
|
|
fprintf( stderr, "\nAt %s:%d\n", __FILE__, __LINE__ ); \
|
|
|
|
abort(); \
|
|
|
|
}})
|
|
|
|
|
|
|
|
#define FAIL( ... ) CHECK( false, __VA_ARGS__ )
|
|
|
|
|
|
|
|
|
|
|
|
// Debug-only versions. Only instantiated in debug builds
|
|
|
|
#ifndef NDEBUG
|
|
|
|
#define DCHECK CHECK
|
|
|
|
#define DFAIL FAIL
|
|
|
|
#else
|
|
|
|
#define DCHECK( ... )
|
|
|
|
#define DFAIL( ... )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|