remote: close file on usteer_init_local_id fread fail
[project/usteer.git] / utils.h
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
14 *
15 * Copyright (C) 2020 embedd.ch
16 * Copyright (C) 2020 Felix Fietkau <nbd@nbd.name>
17 * Copyright (C) 2020 John Crispin <john@phrozen.org>
18 */
19
20 #ifndef __APMGR_UTILS_H
21 #define __APMGR_UTILS_H
22
23 #define MSG(_nr, _format, ...) debug_msg(MSG_##_nr, __func__, __LINE__, _format, ##__VA_ARGS__)
24 #define MSG_CONT(_nr, _format, ...) debug_msg_cont(MSG_##_nr, _format, ##__VA_ARGS__)
25
26 #define MAC_ADDR_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
27 #define MAC_ADDR_DATA(_a) \
28 ((const uint8_t *)(_a))[0], \
29 ((const uint8_t *)(_a))[1], \
30 ((const uint8_t *)(_a))[2], \
31 ((const uint8_t *)(_a))[3], \
32 ((const uint8_t *)(_a))[4], \
33 ((const uint8_t *)(_a))[5]
34
35 enum usteer_debug {
36 MSG_FATAL,
37 MSG_INFO,
38 MSG_VERBOSE,
39 MSG_DEBUG,
40 MSG_NETWORK,
41 MSG_DEBUG_ALL,
42 };
43
44 extern void log_msg(char *msg);
45 extern void debug_msg(int level, const char *func, int line, const char *format, ...);
46 extern void debug_msg_cont(int level, const char *format, ...);
47
48 #define __usteer_init __attribute__((constructor))
49
50 #endif