Defines |
#define | debug(M,...) fprintf(stderr, "DEBUG %s:%d: " M "\n", __FILE__, __LINE__, ##__VA_ARGS__) |
#define | clean_errno() (errno == 0 ? "None" : strerror(errno)) |
#define | log_err(M,...) fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__) |
#define | log_warn(M,...) fprintf(stderr, "[WARNING] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__) |
#define | log_info(M,...) fprintf(stderr, "[INFO] (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__) |
#define | check(A, M,...) if(!(A)) { log_err(M, ##__VA_ARGS__); errno=0; goto error; } |
#define | sentinel(M,...) { log_err(M, ##__VA_ARGS__); errno=0; goto error; } |
#define | check_mem(A) check((A), "Out of memory.") |
#define | check_debug(A, M,...) if(!(A)) { debug(M, ##__VA_ARGS__); errno=0; goto error; } |
Zed's Awesome Debug Macros.
- Author:
- Zed A. Shaw <help@learncodethehardway.org>
Exerpt from "Learn C the hard way", Exercise 20: Zed's Awesome Debug Macros by Zed A. Shaw <help@learncodethehardway.org>.
Adaptation for libdxf: Copyright (C) 2016, 2017 by Bert Timmerman <bert.timmerman@xs4all.nl>.
Copyright Notices.
This program is free software; you can redistribute it and/or modify it under the terms of 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.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to:
Free Software Foundation, Inc.,
59 Temple Place,
Suite 330,
Boston,
MA 02111 USA.
Definition in file dbg.h.
#define check_debug |
( |
|
A, |
|
|
|
M, |
|
|
|
... |
|
) |
| if(!(A)) { debug(M, ##__VA_ARGS__); errno=0; goto error; } |
An alternative macro check_debug
that still checks and handles an error, but if the error is common then you don't want to bother reporting it.
In this one it will use debug
instead of log_err
to report the message, so when you define NDEBUG
the check still happens, the error jump goes off, but the message isn't printed.
Definition at line 116 of file dbg.h.