26 #ifndef TAGLIB_TUTILS_H 27 #define TAGLIB_TUTILS_H 31 #ifndef DO_NOT_DOCUMENT // tell Doxygen not to document this header 41 #if defined(HAVE_MSC_BYTESWAP) 43 #elif defined(HAVE_GLIBC_BYTESWAP) 44 # include <byteswap.h> 45 #elif defined(HAVE_MAC_BYTESWAP) 46 # include <libkern/OSByteOrder.h> 47 #elif defined(HAVE_OPENBSD_BYTESWAP) 48 # include <sys/endian.h> 63 inline unsigned short byteSwap(
unsigned short x)
65 #if defined(HAVE_GCC_BYTESWAP) 67 return __builtin_bswap16(x);
69 #elif defined(HAVE_MSC_BYTESWAP) 71 return _byteswap_ushort(x);
73 #elif defined(HAVE_GLIBC_BYTESWAP) 77 #elif defined(HAVE_MAC_BYTESWAP) 79 return OSSwapInt16(x);
81 #elif defined(HAVE_OPENBSD_BYTESWAP) 87 return ((x >> 8) & 0xff) | ((x & 0xff) << 8);
95 inline unsigned int byteSwap(
unsigned int x)
97 #if defined(HAVE_GCC_BYTESWAP) 99 return __builtin_bswap32(x);
101 #elif defined(HAVE_MSC_BYTESWAP) 103 return _byteswap_ulong(x);
105 #elif defined(HAVE_GLIBC_BYTESWAP) 107 return __bswap_32(x);
109 #elif defined(HAVE_MAC_BYTESWAP) 111 return OSSwapInt32(x);
113 #elif defined(HAVE_OPENBSD_BYTESWAP) 119 return ((x & 0xff000000u) >> 24)
120 | ((x & 0x00ff0000u) >> 8)
121 | ((x & 0x0000ff00u) << 8)
122 | ((x & 0x000000ffu) << 24);
130 inline unsigned long long byteSwap(
unsigned long long x)
132 #if defined(HAVE_GCC_BYTESWAP) 134 return __builtin_bswap64(x);
136 #elif defined(HAVE_MSC_BYTESWAP) 138 return _byteswap_uint64(x);
140 #elif defined(HAVE_GLIBC_BYTESWAP) 142 return __bswap_64(x);
144 #elif defined(HAVE_MAC_BYTESWAP) 146 return OSSwapInt64(x);
148 #elif defined(HAVE_OPENBSD_BYTESWAP) 154 return ((x & 0xff00000000000000ull) >> 56)
155 | ((x & 0x00ff000000000000ull) >> 40)
156 | ((x & 0x0000ff0000000000ull) >> 24)
157 | ((x & 0x000000ff00000000ull) >> 8)
158 | ((x & 0x00000000ff000000ull) << 8)
159 | ((x & 0x0000000000ff0000ull) << 24)
160 | ((x & 0x000000000000ff00ull) << 40)
161 | ((x & 0x00000000000000ffull) << 56);
170 inline String formatString(
const char *format, ...)
175 static const size_t BufferSize = 128;
178 va_start(args, format);
180 char buf[BufferSize];
183 length = std::vsnprintf(buf, BufferSize, format, args);
206 constexpr ByteOrder systemByteOrder()
208 constexpr
union IntCharUnion {
211 constexpr IntCharUnion(
int j) : i(j) {}
A namespace for all TagLib related classes and functions.
Definition: apefile.h:41