Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
1.9 KiB

/* this header file comes from libowfat, http://www.fefe.de/libowfat/ */
21 years ago
#ifndef UINT16_H
#define UINT16_H
#include <inttypes.h> // uint16_t, int16_t
#include <stddef.h> // size_t
#ifdef __cplusplus
extern "C" {
#endif
typedef uint16_t uint16;
typedef int16_t int16;
21 years ago
#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
21 years ago
#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);
21 years ago
#endif
static inline size_t fmt_uint16(char* out, uint16 in) {
if (out) uint16_pack(out,in);
return 2;
}
static inline size_t fmt_uint16_big(char* out, uint16 in) {
if (out) uint16_pack_big(out,in);
return 2;
}
static inline size_t scan_uint16(const char* in, size_t len, uint16_t* b) {
if (len<2) return 0;
*b = uint16_read(in);
return 2;
}
static inline size_t scan_uint16_big(const char* in, size_t len, uint16_t* b) {
if (len<2) return 0;
*b = uint16_read_big(in);
return 2;
}
#ifdef __cplusplus
}
#endif
21 years ago
#endif