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