File: uintnn.h

package info (click to toggle)
bglibs 2.04%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,468 kB
  • sloc: ansic: 15,821; perl: 674; sh: 63; makefile: 29
file content (63 lines) | stat: -rw-r--r-- 2,282 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef BGLIBS__UINTNN__H__
#define BGLIBS__UINTNN__H__

/* These macros are used to produce the declarations and inline
 * definitions for the various uint## pack/unpack msb/lsb functions */

#if defined(__GNUC__) && defined(HAS_UNALIGNED_ACCESSES) && defined(ENDIAN_LSB)
#define __INLINE_UINT_LSB 1
#undef __INLINE_UINT_MSB
#endif

#if defined(__GNUC__) && defined(HAS_UNALIGNED_ACCESSES) && defined(ENDIAN_MSB)
#define __INLINE_UINT_MSB 1
#undef __INLINE_UINT_LSB
#endif

#ifdef __INLINE_UINT_LSB
#define __UINTNN_GET_LSB_DECL(B,N) \
  static __inline__ uint##B uint##B##_get_lsb(const unsigned char b[N]) \
  { return *((const uint##B *)b); }
#define __UINTNN_PACK_LSB_DECL(B,N) \
  static __inline__ void uint##B##_pack_lsb(uint##B u, unsigned char b[N]) \
  { *((uint##B *)b) = u; }
#define __UINTNN_UNPACK_LSB_DECL(B,N) \
  static __inline__ void uint##B##_unpack_lsb(const unsigned char b[N], uint##B *u) \
  { *u = *((uint##B *)b); }
#else
#define __UINTNN_GET_LSB_DECL(B,N) \
  extern uint##B uint##B##_get_lsb(const unsigned char[N]);
#define __UINTNN_PACK_LSB_DECL(B,N) \
  extern void uint##B##_pack_lsb(uint##B, unsigned char[N]);
#define __UINTNN_UNPACK_LSB_DECL(B,N) \
  extern void uint##B##_unpack_lsb(const unsigned char[N], uint##B *);
#endif

#ifdef __INLINE_UINT_MSB
#define __UINTNN_GET_MSB_DECL(B,N) \
  static __inline__ uint##B uint##B##_get_msb(const unsigned char b[N]) \
  { return *((const uint##B *)b); }
#define __UINTNN_PACK_MSB_DECL(B,N) \
  static __inline__ void uint##B##_pack_msb(uint##B u, unsigned char b[N]) \
  { *((uint##B *)b) = u; }
#define __UINTNN_UNPACK_MSB_DECL(B,N) \
  static __inline__ void uint##B##_unpack_msb(const unsigned char b[N], uint##B *u) \
  { *u = *((uint##B *)b); }
#else
#define __UINTNN_GET_MSB_DECL(B,N) \
  extern uint##B uint##B##_get_msb(const unsigned char[N]);
#define __UINTNN_PACK_MSB_DECL(B,N) \
  extern void uint##B##_pack_msb(uint##B, unsigned char[N]);
#define __UINTNN_UNPACK_MSB_DECL(B,N) \
  extern void uint##B##_unpack_msb(const unsigned char[N], uint##B *);
#endif

#define __UINTNN_DECL(B,N) \
  __UINTNN_GET_LSB_DECL(B,N) \
  __UINTNN_PACK_LSB_DECL(B,N) \
  __UINTNN_UNPACK_LSB_DECL(B,N) \
  __UINTNN_GET_MSB_DECL(B,N) \
  __UINTNN_PACK_MSB_DECL(B,N) \
  __UINTNN_UNPACK_MSB_DECL(B,N)

#endif