2 * carlu - userspace testing utility for ar9170 devices
4 * Random assortment of debug stuff
6 * Copyright 2009-2011 Christian Lamparter <chunkeey@googlemail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
37 bool print_message_debug_level;
38 enum debug_level_t debug_level;
45 debug_level = VERBOSE;
47 print_message_debug_level = false;
54 FILE *dbg_lvl_to_fh(const enum debug_level_t lvl)
69 void print_hex_dump_bytes(const enum debug_level_t lvl, const char *pre,
70 const void *buf, size_t len)
74 const unsigned char *tmp = (void *) buf;
78 for (i = 0; i < len; i++) {
81 __fprintf(lvl, "%s%s: %s\n", pre, line, str);
85 pbuf += sprintf(pbuf, "0x%04lx: ", (unsigned long)i);
88 pbuf += sprintf(pbuf, "%.2x ", tmp[i]);
89 str[i % 16] = (isprint(tmp[i]) && isascii(tmp[i])) ? tmp[i] : '.';
95 for (j = 0; j < (16 - (i % 16)); j++)
96 pbuf += sprintf(pbuf, " ");
99 __fprintf(lvl, "%s%s: %s\n", pre, line, str);