Skip to content

Commit

Permalink
add std::endian support if available
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Aug 2, 2023
1 parent 9894c69 commit b832728
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
#include <limits>
#include <set>

#ifdef __cpp_lib_endian
#include <bit>
#endif

// *****************************************************************************
namespace {
using namespace Exiv2;
Expand Down Expand Up @@ -168,7 +172,9 @@ bool Image::isPrintICC(uint16_t type, Exiv2::PrintStructureOption option) {
}

bool Image::isBigEndianPlatform() {
#ifdef __LITTLE_ENDIAN__
#ifdef __cpp_lib_endian
return std::endian::native == std::endian::big;
#elif defined(__LITTLE_ENDIAN__)
return false;
#elif defined(__BIG_ENDIAN__)
return true;
Expand All @@ -188,7 +194,9 @@ bool Image::isBigEndianPlatform() {
#endif
}
bool Image::isLittleEndianPlatform() {
#ifdef __LITTLE_ENDIAN__
#ifdef __cpp_lib_endian
return std::endian::native == std::endian::little;
#elif defined(__LITTLE_ENDIAN__)
return true;
#else
return !isBigEndianPlatform();
Expand Down

0 comments on commit b832728

Please sign in to comment.