MySQL 8.1.0
Source Code Documentation
little_endian.h
Go to the documentation of this file.
1#ifndef LITTLE_ENDIAN_INCLUDED
2#define LITTLE_ENDIAN_INCLUDED
3/* Copyright (c) 2012, 2023, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8
9 This program is also distributed with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have included with MySQL.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License, version 2.0, for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
24
25/**
26 @file include/little_endian.h
27 Data in little-endian format.
28*/
29
30// IWYU pragma: private, include "my_byteorder.h"
31
32#ifndef MY_BYTEORDER_INCLUDED
33#error This file should never be #included directly; use my_byteorder.h.
34#endif
35
36#include <string.h>
37
38#include "my_inttypes.h"
39
40/*
41 Since the pointers may be misaligned, we cannot do a straight read out of
42 them. (It usually works-by-accident on x86 and on modern ARM, but not always
43 when the compiler chooses unusual instruction for the read, e.g. LDM on ARM
44 or most SIMD instructions on x86.) memcpy is safe and gets optimized to a
45 single operation, since the size is small and constant.
46*/
47
48static inline int16 sint2korr(const uchar *A) {
49 int16 ret;
50 memcpy(&ret, A, sizeof(ret));
51 return ret;
52}
53
54static inline int32 sint4korr(const uchar *A) {
55 int32 ret;
56 memcpy(&ret, A, sizeof(ret));
57 return ret;
58}
59
60static inline uint16 uint2korr(const uchar *A) {
61 uint16 ret;
62 memcpy(&ret, A, sizeof(ret));
63 return ret;
64}
65
66static inline uint32 uint4korr(const uchar *A) {
67 uint32 ret;
68 memcpy(&ret, A, sizeof(ret));
69 return ret;
70}
71
72static inline ulonglong uint8korr(const uchar *A) {
73 ulonglong ret;
74 memcpy(&ret, A, sizeof(ret));
75 return ret;
76}
77
78static inline longlong sint8korr(const uchar *A) {
79 longlong ret;
80 memcpy(&ret, A, sizeof(ret));
81 return ret;
82}
83
84static inline void int2store(uchar *T, uint16 A) { memcpy(T, &A, sizeof(A)); }
85
86static inline void int4store(uchar *T, uint32 A) { memcpy(T, &A, sizeof(A)); }
87
88static inline void int7store(uchar *T, ulonglong A) { memcpy(T, &A, 7); }
89
90static inline void int8store(uchar *T, ulonglong A) {
91 memcpy(T, &A, sizeof(A));
92}
93
94static inline float float4get(const uchar *M) {
95 float V;
96 memcpy(&V, (M), sizeof(float));
97 return V;
98}
99
100static inline void float4store(uchar *V, float M) {
101 memcpy(V, (&M), sizeof(float));
102}
103
104static inline double float8get(const uchar *M) {
105 double V;
106 memcpy(&V, M, sizeof(double));
107 return V;
108}
109
110static inline void float8store(uchar *V, double M) {
111 memcpy(V, &M, sizeof(double));
112}
113
114#endif /* LITTLE_ENDIAN_INCLUDED */
#define M
Definition: ctype-tis620.cc:72
static double float8get(const uchar *M)
Definition: little_endian.h:104
static void int8store(uchar *T, ulonglong A)
Definition: little_endian.h:90
static void int4store(uchar *T, uint32 A)
Definition: little_endian.h:86
static float float4get(const uchar *M)
Definition: little_endian.h:94
static void float8store(uchar *V, double M)
Definition: little_endian.h:110
static void int7store(uchar *T, ulonglong A)
Definition: little_endian.h:88
static int16 sint2korr(const uchar *A)
Definition: little_endian.h:48
static void int2store(uchar *T, uint16 A)
Definition: little_endian.h:84
static uint16 uint2korr(const uchar *A)
Definition: little_endian.h:60
static ulonglong uint8korr(const uchar *A)
Definition: little_endian.h:72
static uint32 uint4korr(const uchar *A)
Definition: little_endian.h:66
static int32 sint4korr(const uchar *A)
Definition: little_endian.h:54
static longlong sint8korr(const uchar *A)
Definition: little_endian.h:78
static void float4store(uchar *V, float M)
Definition: little_endian.h:100
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
unsigned char uchar
Definition: my_inttypes.h:51
long long int longlong
Definition: my_inttypes.h:54
int16_t int16
Definition: my_inttypes.h:63
int32_t int32
Definition: my_inttypes.h:65
uint16_t uint16
Definition: my_inttypes.h:64
uint32_t uint32
Definition: my_inttypes.h:66