Electroneum
macros.h
Go to the documentation of this file.
1 /* $Id: macros.h,v 1.1 2012/04/30 20:37:56 nanard Exp $ */
2 /* MiniUPnP project
3  * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
4  * (c) 2012-2015 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 #include <stdint.h>
14 
15 #ifndef INLINE
16 #define INLINE static inline
17 #endif
18 /* theses macros are designed to read/write unsigned short/long int
19  * from an unsigned char array in network order (big endian).
20  * Avoid pointer casting, so avoid accessing unaligned memory, which
21  * can crash with some cpu's */
23 {
24  return (p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]);
25 }
26 #define READNU32(p) readnu32(p)
28 {
29  return (p[0] << 8 | p[1]);
30 }
31 #define READNU16(p) readnu16(p)
33 {
34  p[0] = (n & 0xff000000) >> 24;
35  p[1] = (n & 0xff0000) >> 16;
36  p[2] = (n & 0xff00) >> 8;
37  p[3] = n & 0xff;
38 }
39 #define WRITENU32(p, n) writenu32(p, n)
41 {
42  p[0] = (n & 0xff00) >> 8;
43  p[1] = n & 0xff;
44 }
45 #define WRITENU16(p, n) writenu16(p, n)
46 
47 #endif /* MACROS_H_INCLUDED */
#define INLINE
Definition: macros.h:16
INLINE uint16_t readnu16(const uint8_t *p)
Definition: macros.h:27
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:22
unsigned int uint32_t
Definition: stdint.h:126
INLINE void writenu16(uint8_t *p, uint16_t n)
Definition: macros.h:40
INLINE void writenu32(uint8_t *p, uint32_t n)
Definition: macros.h:32