Path: blob/main/crypto/openssl/include/internal/endian.h
34879 views
/*1* Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89#ifndef OSSL_INTERNAL_ENDIAN_H10# define OSSL_INTERNAL_ENDIAN_H11# pragma once1213/*14* IS_LITTLE_ENDIAN and IS_BIG_ENDIAN can be used to detect the endianness15* at compile time. To use it, DECLARE_IS_ENDIAN must be used to declare16* a variable.17*18* L_ENDIAN and B_ENDIAN can be used at preprocessor time. They can be set19* in the configarion using the lib_cppflags variable. If neither is20* set, it will fall back to code works with either endianness.21*/2223# if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__)24# define DECLARE_IS_ENDIAN const int ossl_is_little_endian = __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__25# define IS_LITTLE_ENDIAN (ossl_is_little_endian)26# define IS_BIG_ENDIAN (!ossl_is_little_endian)27# if defined(L_ENDIAN) && (__BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__)28# error "L_ENDIAN defined on a big endian machine"29# endif30# if defined(B_ENDIAN) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)31# error "B_ENDIAN defined on a little endian machine"32# endif33# if !defined(L_ENDIAN) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)34# define L_ENDIAN35# endif36# if !defined(B_ENDIAN) && (__BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__)37# define B_ENDIAN38# endif39# else40# define DECLARE_IS_ENDIAN \41const union { \42long one; \43char little; \44} ossl_is_endian = { 1 }4546# define IS_LITTLE_ENDIAN (ossl_is_endian.little != 0)47# define IS_BIG_ENDIAN (ossl_is_endian.little == 0)48# endif4950#endif515253