ev3duder  0.3.0
EV3 Downloader/Uploader
defs.h
Go to the documentation of this file.
1 #ifndef EV3DUDER_DEFS_H
2 #define EV3DUDER_DEFS_H
3 
4 #include <stdint.h>
5 #include <stddef.h>
6 #include <string.h>
7 
8 // shorter type names
9 typedef uint8_t u8;
10 typedef uint16_t u16;
11 typedef uint32_t u32;
12 typedef uint64_t u64;
13 
14 typedef int8_t i8;
15 typedef int16_t i16;
16 typedef int32_t i32;
17 typedef int64_t i64;
18 
19 #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array)[0])
20 
21 #define die(msg) \
22  do {\
23  fprintf(stderr, "[%s:%d]: %ls (%s)", __func__, __LINE__, hid_error(handle), msg);\
24  exit(__LINE__);\
25  } while (0)
26 
27 #ifndef _GNU_SOURCE
28 static inline void *mempcpy(void * restrict dst, const void * restrict src, size_t len) {
30  return (char*)memcpy(dst, src, len) + len;
31 }
32 #endif
33 
34 #define print_bytes(buf, len) \
35  do {\
36  u8 *ptr = (u8*)buf;\
37  for (int i = 0; i != len; i++, ptr++) fprintf(stderr, "%02x ", *ptr);\
38  } while (0*putc('\n', stderr))
39 
40 #define print_chars(buf, len) \
41  do {\
42  char *ptr = buf;\
43  for (int i = 0; i != len; i++, ptr++) fprintf(stderr, "%c ", *ptr);\
44  } while (0*putc('\n', stderr))
45 
46 #define TIMEOUT 2000 /* in milliseconds */
47 
48 #endif
49 
int64_t i64
Definition: defs.h:17
int8_t i8
Definition: defs.h:14
int16_t i16
Definition: defs.h:15
uint32_t u32
Definition: defs.h:11
uint16_t u16
Definition: defs.h:10
int32_t i32
Definition: defs.h:16
uint64_t u64
Definition: defs.h:12
uint8_t u8
Definition: defs.h:9