X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=include%2Flttngerr.h;h=2ba5b32b219f9c4d1066bfbeeced6bb419a6f6c1;hp=5c3d8c4fb824a8e877d7e445e6fac389cd5bf772;hb=57d0d50175ef25d3171bb8be9e9c30aba77674fe;hpb=fac6795d6e2c60e79bdc7dab42da94d2025a57d3 diff --git a/include/lttngerr.h b/include/lttngerr.h index 5c3d8c4fb..2ba5b32b2 100644 --- a/include/lttngerr.h +++ b/include/lttngerr.h @@ -1,4 +1,5 @@ -/* Copyright (C) 2011 - David Goulet +/* + * Copyright (C) 2011 - David Goulet * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -13,14 +14,17 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * */ #ifndef _LTTNGERR_H #define _LTTNGERR_H #include -#include +#include + +/* Stringify the expansion of a define */ +#define XSTR(d) STR(d) +#define STR(s) #s extern int opt_quiet; extern int opt_verbose; @@ -36,29 +40,24 @@ enum __lttng_print_type { /* * __lttng_print * - * Internal function for printing message - * depending on command line option and verbosity. + * Macro for printing message depending on + * command line option and verbosity. */ -void __lttng_print(enum __lttng_print_type type, const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - - if (opt_quiet == 0) { - if (type == PRINT_MSG || (opt_verbose && type == PRINT_DBG)) { - vfprintf(stdout, fmt, ap); - } else if (type != PRINT_MSG && type != PRINT_DBG) { - vfprintf(stderr, fmt, ap); - } - } - - va_end(ap); -} +#define __lttng_print(type, fmt, args...) \ + do { \ + if (opt_quiet == 0) { \ + if (type == PRINT_MSG || (opt_verbose && type == PRINT_DBG)) { \ + fprintf(stdout, fmt, ## args); \ + } else if (type != PRINT_MSG && type != PRINT_DBG) { \ + fprintf(stderr, fmt, ## args); \ + } \ + } \ + } while (0); #define MSG(fmt, args...) __lttng_print(PRINT_MSG, fmt "\n", ## args) #define ERR(fmt, args...) __lttng_print(PRINT_ERR, "Error: " fmt "\n", ## args) #define WARN(fmt, args...) __lttng_print(PRINT_WARN, "Warning: " fmt "\n", ## args) #define BUG(fmt, args...) __lttng_print(PRINT_BUG, "BUG: " fmt "\n", ## args) -#define DBG(fmt, args...) __lttng_print(PRINT_DBG, "DEBUG: " fmt "\n", ## args) +#define DBG(fmt, args...) __lttng_print(PRINT_DBG, "DEBUG: " fmt " [in %s() at " __FILE__ ":" XSTR(__LINE__) "]\n", ## args, __func__) #endif /* _LTTNGERR_H */