Use `pubsetbuf` only with `libstdc++`

This usage of the function seems only to work as intended with that
standard lib. With `libc++` and the MSVC standard lib the call has no
effect.
This commit is contained in:
Martchus 2023-02-28 21:06:52 +01:00
parent 981db492e4
commit d80736743b
2 changed files with 14 additions and 1 deletions

View File

@ -717,7 +717,11 @@ Popularity TagValue::toPopularity() const
auto reader = BinaryReader(&s);
try {
s.exceptions(std::ios_base::failbit | std::ios_base::badbit);
#if defined(__GLIBCXX__) && !defined(_LIBCPP_VERSION)
s.rdbuf()->pubsetbuf(m_ptr.get(), static_cast<std::streamsize>(m_size));
#else
s.write(m_ptr.get(), static_cast<std::streamsize>(m_size));
#endif
popularity.user = reader.readLengthPrefixedString();
popularity.rating = reader.readFloat64LE();
popularity.playCounter = reader.readUInt64LE();

View File

@ -78,7 +78,11 @@ template <class StreamType> void VorbisCommentField::internalParse(StreamType &s
auto decoded = decodeBase64(data.get() + idSize + 1, size - idSize - 1);
stringstream bufferStream(ios_base::in | ios_base::out | ios_base::binary);
bufferStream.exceptions(ios_base::failbit | ios_base::badbit);
#if defined(__GLIBCXX__) && !defined(_LIBCPP_VERSION)
bufferStream.rdbuf()->pubsetbuf(reinterpret_cast<char *>(decoded.first.get()), decoded.second);
#else
bufferStream.write(reinterpret_cast<const char *>(decoded.first.get()), decoded.second);
#endif
FlacMetaDataBlockPicture pictureBlock(value());
pictureBlock.parse(bufferStream, decoded.second);
setTypeInfo(pictureBlock.pictureType());
@ -197,10 +201,15 @@ bool VorbisCommentField::make(BinaryWriter &writer, VorbisCommentFlags flags, Di
auto buffer = make_unique<char[]>(requiredSize);
stringstream bufferStream(ios_base::in | ios_base::out | ios_base::binary);
bufferStream.exceptions(ios_base::failbit | ios_base::badbit);
#if defined(__GLIBCXX__) && !defined(_LIBCPP_VERSION)
bufferStream.rdbuf()->pubsetbuf(buffer.get(), requiredSize);
#endif
pictureBlock.make(bufferStream);
#if defined(__GLIBCXX__) && !defined(_LIBCPP_VERSION)
bufferStream.read(buffer.get(), static_cast<std::streamsize>(requiredSize));
#endif
valueString = encodeBase64(reinterpret_cast<std::uint8_t *>(buffer.get()), requiredSize);
} catch (const Failure &) {
diag.emplace_back(DiagLevel::Critical, "Unable to make METADATA_BLOCK_PICTURE struct from the assigned value.", context);
throw;