1/** 2 * error.c 3 * 4 * error reporting routines 5 * basicly wrappers around printf 6 * 7 * (c) 2005 NLnet Labs 8 * 9 * See the file LICENSE for the license 10 * 11 */ 12 13#include "drill.h" 14#include <ldns/ldns.h> 15 16static void 17warning_va_list(const char *fmt, va_list args) 18{ 19 fprintf(stderr, "Warning: "); 20 vfprintf(stderr, fmt, args); 21 fprintf(stderr, "\n"); 22} 23 24void 25warning(const char *fmt, ...) 26{ 27 va_list args; 28 va_start(args, fmt); 29 warning_va_list(fmt, args); 30 va_end(args); 31} 32 33static void 34error_va_list(const char *fmt, va_list args) 35{ 36 fprintf(stderr, "Error: "); 37 vfprintf(stderr, fmt, args); 38 fprintf(stderr, "\n"); 39} 40 41void 42error(const char *fmt, ...) 43{ 44 va_list args; 45 va_start(args, fmt); 46 error_va_list(fmt, args); 47 va_end(args); 48 exit(EXIT_FAILURE); 49} 50 51static void 52verbose_va_list(const char *fmt, va_list args) 53{ 54 vfprintf(stdout, fmt, args); 55 fprintf(stdout, "\n"); 56} 57 58/* print stuff */ 59void 60mesg(const char *fmt, ...) 61{ 62 va_list args; 63 if (verbosity == -1) { 64 return; 65 } 66 fprintf(stdout, ";; "); 67 va_start(args, fmt); 68 verbose_va_list(fmt, args); 69 va_end(args); 70} 71 72/* print stuff when in verbose mode (1) */ 73void 74verbose(const char *fmt, ...) 75{ 76 va_list args; 77 if (verbosity < 1) { 78 return; 79 } 80 81 va_start(args, fmt); 82 verbose_va_list(fmt, args); 83 va_end(args); 84} 85 86/* print stuff when in vverbose mode (2) */ 87void 88vverbose(const char *fmt, ...) 89{ 90 va_list args; 91 if (verbosity < 2) { 92 return; 93 } 94 95 va_start(args, fmt); 96 verbose_va_list(fmt, args); 97 va_end(args); 98} 99 100static void 101debug_va_list(const char *fmt, va_list args) 102{ 103 vfprintf(stderr, fmt, args); 104 fprintf(stderr, "\n"); 105} 106 107void 108debug(const char *fmt, ...) 109{ 110 va_list args; 111 fprintf(stderr, "[DEBUG] "); 112 va_start(args, fmt); 113 debug_va_list(fmt, args); 114 va_end(args); 115} 116