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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/**
* memory-private.h
*
* Copyright (c) 2013
* libchewing Core Team. See ChangeLog for details.
*
* See the file "COPYING" for information on usage and redistribution
* of this file.
*/
/* *INDENT-OFF* */
#ifndef _CHEWING_MEMORY_PRIVATE_H
#define _CHEWING_MEMORY_PRIVATE_H
/* *INDENT-ON* */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#elif defined HAVE_STDINT_H
# include <stdint.h>
#endif
#ifdef _MSC_VER
# define inline __inline
#endif
static inline uint16_t GetUint16(const void *ptr)
{
uint16_t val;
const unsigned char *uptr = ptr;
val = (uptr[0] << 0) | (uptr[1] << 8);
return val;
}
static inline void PutUint16(uint16_t val, void *ptr)
{
unsigned char *uptr = (unsigned char *) ptr;
uptr[0] = (val >> 0) & 0xff;
uptr[1] = (val >> 8) & 0xff;
}
static inline uint16_t GetUint16PreservedEndian(const void *ptr)
{
uint16_t val;
const unsigned char *uptr = ptr;
#if WORDS_BIGENDIAN
val = (uptr[0] << 8) | (uptr[1] << 0);
#else
val = (uptr[0] << 0) | (uptr[1] << 8);
#endif
return val;
}
static inline void PutUint16PreservedEndian(uint16_t val, void *ptr)
{
unsigned char *uptr = (unsigned char *) ptr;
#if WORDS_BIGENDIAN
uptr[0] = (val >> 8) & 0xff;
uptr[1] = (val >> 0) & 0xff;
#else
uptr[0] = (val >> 0) & 0xff;
uptr[1] = (val >> 8) & 0xff;
#endif
}
/*
* This function is specially used in reading fields of TreeType which are
* compressed into 3 bytes, so it has a special name of 24.
*/
static inline uint32_t GetUint24(const void *ptr)
{
uint32_t val;
const unsigned char *uptr = ptr;
val = (uptr[0] << 0) | (uptr[1] << 8) | (uptr[2] << 16);
return val;
}
/*
* This function is specially used in writing fields of TreeType which are
* compressed into 3 bytes, so it has a special name of 24.
*/
static inline void PutUint24(uint32_t val, void *ptr)
{
unsigned char *uptr = (unsigned char *) ptr;
uptr[0] = (val >> 0) & 0xff;
uptr[1] = (val >> 8) & 0xff;
uptr[2] = (val >> 16) & 0xff;
}
static inline int GetInt32PreservedEndian(const void *ptr)
{
int val;
const unsigned char *uptr = ptr;
#if WORDS_BIGENDIAN
val = (uptr[0] << 24) | (uptr[1] << 16) | (uptr[2] << 8) | (uptr[3] << 0);
#else
val = (uptr[0] << 0) | (uptr[1] << 8) | (uptr[2] << 16) | (uptr[3] << 24);
#endif
return val;
}
static inline void PutInt32PreservedEndian(int val, void *ptr)
{
unsigned char *uptr = (unsigned char *) ptr;
#if WORDS_BIGENDIAN
uptr[0] = (val >> 24) & 0xff;
uptr[1] = (val >> 16) & 0xff;
uptr[2] = (val >> 8) & 0xff;
uptr[3] = (val >> 0) & 0xff;
#else
uptr[0] = (val >> 0) & 0xff;
uptr[1] = (val >> 8) & 0xff;
uptr[2] = (val >> 16) & 0xff;
uptr[3] = (val >> 24) & 0xff;
#endif
}
/* *INDENT-OFF* */
#endif
/* *INDENT-ON* */
|