Monero
macros.h
Go to the documentation of this file.
1 /* $Id: macros.h,v 1.5 2019/09/24 09:37:52 nanard Exp $ */
2 /* MiniUPnP project
3  * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
4  * (c) 2012-2019 Thomas Bernard
5  * This software is subject to the conditions detailed
6  * in the LICENCE file provided within the distribution */
7 
8 #ifndef MACROS_H_INCLUDED
9 #define MACROS_H_INCLUDED
10 
11 #define UNUSED(arg) (void)(arg)
12 
13 #if defined(__GNUC__) && (__GNUC__ >= 7)
14 #define FALL_THROUGH __attribute__((fallthrough))
15 #else
16 #define FALL_THROUGH
17 #endif
18 
19 #include <stdint.h>
20 
21 #ifndef INLINE
22 #define INLINE static inline
23 #endif
24 /* theses macros are designed to read/write unsigned short/long int
25  * from an unsigned char array in network order (big endian).
26  * Avoid pointer casting, so avoid accessing unaligned memory, which
27  * can crash with some cpu's */
29 {
30  return (p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]);
31 }
32 #define READNU32(p) readnu32(p)
34 {
35  return (p[0] << 8 | p[1]);
36 }
37 #define READNU16(p) readnu16(p)
39 {
40  p[0] = (n & 0xff000000) >> 24;
41  p[1] = (n & 0xff0000) >> 16;
42  p[2] = (n & 0xff00) >> 8;
43  p[3] = n & 0xff;
44 }
45 #define WRITENU32(p, n) writenu32(p, n)
47 {
48  p[0] = (n & 0xff00) >> 8;
49  p[1] = n & 0xff;
50 }
51 #define WRITENU16(p, n) writenu16(p, n)
52 
53 #endif /* MACROS_H_INCLUDED */
#define INLINE
Definition: macros.h:22
INLINE uint16_t readnu16(const uint8_t *p)
Definition: macros.h:33
unsigned short uint16_t
Definition: stdint.h:125
unsigned char uint8_t
Definition: stdint.h:124
INLINE uint32_t readnu32(const uint8_t *p)
Definition: macros.h:28
unsigned int uint32_t
Definition: stdint.h:126
INLINE void writenu16(uint8_t *p, uint16_t n)
Definition: macros.h:46
INLINE void writenu32(uint8_t *p, uint32_t n)
Definition: macros.h:38
p
Definition: pymoduletest.py:75