summaryrefslogtreecommitdiff
path: root/uint16.h
blob: 091e51a6b74214f879a374e924afeb9b8b98b184 (plain)
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
64
65
/* this header file comes from libowfat, http://www.fefe.de/libowfat/ */
#ifndef UINT16_H
#define UINT16_H

#include <inttypes.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef uint16_t uint16;
typedef int16_t int16;

#if (defined(__i386__) || defined(__x86_64__)) && !defined(NO_UINT16_MACROS)

static inline void uint16_pack(char* out,uint16 in) {
  *(uint16*)out=in;
}

static inline void uint16_unpack(const char *in,uint16* out) {
  *out=*(const uint16*)in;
}

static inline uint16 uint16_read(const char* in) {
  return *(const uint16*)in;
}

#if defined(__x86_64__) && defined(__GNUC__)

static inline void uint16_pack_big(char* out,uint16 in) {
  *(uint16*)out=__builtin_bswap16(in);
}

static inline void uint16_unpack_big(const char *in,uint16* out) {
  *out=__builtin_bswap16(*(const uint16*)in);
}

static inline uint16 uint16_read_big(const char* in) {
  return __builtin_bswap16(*(const uint16*)in);
}

#else

void uint16_pack_big(char *out,uint16 in);
void uint16_unpack_big(const char *in,uint16* out);
uint16 uint16_read_big(const char *in);

#endif

#else

void uint16_pack(char *out,uint16 in);
void uint16_pack_big(char *out,uint16 in);
void uint16_unpack(const char *in,uint16* out);
void uint16_unpack_big(const char *in,uint16* out);
uint16 uint16_read(const char *in);
uint16 uint16_read_big(const char *in);

#endif

#ifdef __cplusplus
}
#endif

#endif