2003-01-09 13:36:05 +01:00
|
|
|
/* logging.h
|
2010-03-10 18:22:23 +01:00
|
|
|
* Copyright (C) 1999, 2000, 2001, 2004, 2006,
|
|
|
|
* 2010 Free Software Foundation, Inc.
|
2003-01-09 13:36:05 +01:00
|
|
|
*
|
2015-04-24 16:42:28 +02:00
|
|
|
* This file is part of GnuPG.
|
2003-01-09 13:36:05 +01:00
|
|
|
*
|
2017-02-24 13:48:28 +01:00
|
|
|
* GnuPG is free software; you can redistribute and/or modify this
|
|
|
|
* part of GnuPG under the terms of either
|
2011-09-30 12:52:11 +02:00
|
|
|
*
|
|
|
|
* - the GNU Lesser General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 3 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* or
|
|
|
|
*
|
|
|
|
* - the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* or both in parallel, as here.
|
2003-01-09 13:36:05 +01:00
|
|
|
*
|
2015-04-24 16:42:28 +02:00
|
|
|
* GnuPG is distributed in the hope that it will be useful, but
|
2006-10-02 13:54:35 +02:00
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2011-09-30 12:52:11 +02:00
|
|
|
* General Public License for more details.
|
2003-01-09 13:36:05 +01:00
|
|
|
*
|
2011-09-30 12:52:11 +02:00
|
|
|
* You should have received a copies of the GNU General Public License
|
|
|
|
* and the GNU Lesser General Public License along with this program;
|
2016-11-05 12:02:19 +01:00
|
|
|
* if not, see <https://www.gnu.org/licenses/>.
|
2003-01-09 13:36:05 +01:00
|
|
|
*/
|
|
|
|
|
2015-04-24 16:42:28 +02:00
|
|
|
#ifndef GNUPG_COMMON_LOGGING_H
|
|
|
|
#define GNUPG_COMMON_LOGGING_H
|
2003-01-09 13:36:05 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-04-24 15:19:10 +02:00
|
|
|
#include <stdarg.h>
|
2015-09-29 13:20:26 +02:00
|
|
|
#include <gpg-error.h>
|
2003-01-09 13:36:05 +01:00
|
|
|
#include "mischelp.h"
|
2010-08-18 21:25:15 +02:00
|
|
|
#include "w32help.h"
|
2003-01-09 13:36:05 +01:00
|
|
|
|
2018-06-12 13:46:00 +02:00
|
|
|
/* We use the libgpg-error provided log functions. but we need one
|
|
|
|
* more function: */
|
|
|
|
#ifdef GPGRT_HAVE_MACRO_FUNCTION
|
2017-11-27 15:00:25 +01:00
|
|
|
# define BUG() bug_at ( __FILE__, __LINE__, __FUNCTION__)
|
|
|
|
static inline void bug_at (const char *file, int line, const char *func)
|
|
|
|
GPGRT_ATTR_NORETURN;
|
|
|
|
static inline void
|
|
|
|
bug_at (const char *file, int line, const char *func)
|
|
|
|
{
|
2017-12-11 10:37:30 +01:00
|
|
|
gpgrt_log (GPGRT_LOGLVL_BUG, "there is a bug at %s:%d:%s\n",
|
|
|
|
file, line, func);
|
2017-11-27 15:00:25 +01:00
|
|
|
abort ();
|
|
|
|
}
|
2018-06-12 13:46:00 +02:00
|
|
|
#else
|
2017-11-27 15:00:25 +01:00
|
|
|
# define BUG() bug_at ( __FILE__, __LINE__)
|
|
|
|
static inline void bug_at (const char *file, int line)
|
|
|
|
GPGRT_ATTR_NORETURN;
|
|
|
|
static inline void
|
|
|
|
bug_at (const char *file, int line)
|
|
|
|
{
|
2017-12-11 10:37:30 +01:00
|
|
|
gpgrt_log (GPGRT_LOGLVL_BUG, "there is a bug at %s:%d\n", file, line);
|
2017-11-27 15:00:25 +01:00
|
|
|
abort ();
|
|
|
|
}
|
2016-04-29 11:04:04 +02:00
|
|
|
#endif /*!GPGRT_HAVE_MACRO_FUNCTION*/
|
2003-01-09 13:36:05 +01:00
|
|
|
|
2013-01-07 16:51:24 +01:00
|
|
|
|
2003-01-09 13:36:05 +01:00
|
|
|
|
2017-12-22 12:55:32 +01:00
|
|
|
/* Some handy assertion macros which don't abort. */
|
|
|
|
|
|
|
|
#define return_if_fail(expr) do { \
|
|
|
|
if (!(expr)) { \
|
|
|
|
log_debug ("%s:%d: assertion '%s' failed\n", \
|
|
|
|
__FILE__, __LINE__, #expr ); \
|
|
|
|
return; \
|
|
|
|
} } while (0)
|
|
|
|
#define return_null_if_fail(expr) do { \
|
|
|
|
if (!(expr)) { \
|
|
|
|
log_debug ("%s:%d: assertion '%s' failed\n", \
|
|
|
|
__FILE__, __LINE__, #expr ); \
|
|
|
|
return NULL; \
|
|
|
|
} } while (0)
|
|
|
|
#define return_val_if_fail(expr,val) do { \
|
|
|
|
if (!(expr)) { \
|
|
|
|
log_debug ("%s:%d: assertion '%s' failed\n", \
|
|
|
|
__FILE__, __LINE__, #expr ); \
|
|
|
|
return (val); \
|
|
|
|
} } while (0)
|
|
|
|
#define never_reached() do { \
|
|
|
|
log_debug ("%s:%d: oops - should never get here\n", \
|
|
|
|
__FILE__, __LINE__ ); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
2015-04-24 16:42:28 +02:00
|
|
|
#endif /*GNUPG_COMMON_LOGGING_H*/
|