26 #ifndef TAGLIB_TUTILS_H
27 #define TAGLIB_TUTILS_H
31 #ifndef DO_NOT_DOCUMENT
37 #if defined(HAVE_MSC_BYTESWAP)
39 #elif defined(HAVE_GLIBC_BYTESWAP)
40 # include <byteswap.h>
41 #elif defined(HAVE_MAC_BYTESWAP)
42 # include <libkern/OSByteOrder.h>
43 #elif defined(HAVE_OPENBSD_BYTESWAP)
44 # include <sys/endian.h>
62 inline unsigned short byteSwap(
unsigned short x)
64 #if defined(HAVE_GCC_BYTESWAP)
66 return __builtin_bswap16(x);
68 #elif defined(HAVE_MSC_BYTESWAP)
70 return _byteswap_ushort(x);
72 #elif defined(HAVE_GLIBC_BYTESWAP)
76 #elif defined(HAVE_MAC_BYTESWAP)
78 return OSSwapInt16(x);
80 #elif defined(HAVE_OPENBSD_BYTESWAP)
86 return ((x >> 8) & 0xff) | ((x & 0xff) << 8);
94 inline unsigned int byteSwap(
unsigned int x)
96 #if defined(HAVE_GCC_BYTESWAP)
98 return __builtin_bswap32(x);
100 #elif defined(HAVE_MSC_BYTESWAP)
102 return _byteswap_ulong(x);
104 #elif defined(HAVE_GLIBC_BYTESWAP)
106 return __bswap_32(x);
108 #elif defined(HAVE_MAC_BYTESWAP)
110 return OSSwapInt32(x);
112 #elif defined(HAVE_OPENBSD_BYTESWAP)
118 return ((x & 0xff000000u) >> 24)
119 | ((x & 0x00ff0000u) >> 8)
120 | ((x & 0x0000ff00u) << 8)
121 | ((x & 0x000000ffu) << 24);
129 inline unsigned long long byteSwap(
unsigned long long x)
131 #if defined(HAVE_GCC_BYTESWAP)
133 return __builtin_bswap64(x);
135 #elif defined(HAVE_MSC_BYTESWAP)
137 return _byteswap_uint64(x);
139 #elif defined(HAVE_GLIBC_BYTESWAP)
141 return __bswap_64(x);
143 #elif defined(HAVE_MAC_BYTESWAP)
145 return OSSwapInt64(x);
147 #elif defined(HAVE_OPENBSD_BYTESWAP)
153 return ((x & 0xff00000000000000ull) >> 56)
154 | ((x & 0x00ff000000000000ull) >> 40)
155 | ((x & 0x0000ff0000000000ull) >> 24)
156 | ((x & 0x000000ff00000000ull) >> 8)
157 | ((x & 0x00000000ff000000ull) << 8)
158 | ((x & 0x0000000000ff0000ull) << 24)
159 | ((x & 0x000000000000ff00ull) << 40)
160 | ((x & 0x00000000000000ffull) << 56);
169 inline String formatString(
const char *format, ...)
174 static const size_t BufferSize = 128;
177 va_start(args, format);
179 char buf[BufferSize];
182 #if defined(HAVE_VSNPRINTF)
184 length = vsnprintf(buf, BufferSize, format, args);
186 #elif defined(HAVE_VSPRINTF_S)
188 length = vsprintf_s(buf, format, args);
194 length = vsprintf(buf, format, args);
195 if(length >= BufferSize) {
196 debug(
"Utils::formatString() - Buffer overflow! Returning an empty string.");
224 inline ByteOrder systemByteOrder()
A namespace for all TagLib related classes and functions.
Definition: apefile.h:41