diff --git a/src/Riff.c b/src/Riff.c index 5181ba1..e86aa2c 100644 --- a/src/Riff.c +++ b/src/Riff.c @@ -137,13 +137,13 @@ char const* DmRiff_readString(DmRiff* slf) { return str; } -char16_t* DmRiff_readStringUtf(DmRiff* slf) { +uint16_t* DmRiff_readStringUtf(DmRiff* slf) { if (slf == NULL) { - return u""; + return NULL; } - char16_t* mem = (char16_t*) slf->mem; - char16_t* str = (char16_t*) slf->mem + slf->pos; + uint16_t* mem = (uint16_t*) slf->mem; + uint16_t* str = (uint16_t*) slf->mem + slf->pos; while (mem[slf->pos] != 0) { slf->pos += 1; diff --git a/src/_Internal.h b/src/_Internal.h index ca39d09..717781f 100644 --- a/src/_Internal.h +++ b/src/_Internal.h @@ -12,7 +12,6 @@ #include #include -#include typedef enum DmResolveFlags { DmResolve_AFTER_PREPARE_TIME = 1 << 10, diff --git a/src/_Riff.h b/src/_Riff.h index 10287d9..5d67092 100644 --- a/src/_Riff.h +++ b/src/_Riff.h @@ -2,7 +2,6 @@ // SPDX-License-Identifier: MIT-Modern-Variant #pragma once #include -#include #define DM_FOURCC(a, b, c, d) (((d) << 24U) | ((c) << 16U) | ((b) << 8U) | (a)) #define DM_FOURCC_RIFF DM_FOURCC('R', 'I', 'F', 'F') @@ -118,7 +117,7 @@ DMINT void DmInfo_parse(DmInfo* slf, DmRiff* rif); DMINT void DmVersion_parse(DmVersion* slf, DmRiff* rif); DMINT void DmReference_parse(DmReference* slf, DmRiff* rif); -DMINT char* Dm_utf16ToUtf8Inline(char* out, char16_t const* u16); +DMINT char* Dm_utf16ToUtf8Inline(char* out, uint16_t const* u16); DMINT bool DmRiff_init(DmRiff* slf, void const* buf, size_t len); DMINT bool DmRiff_is(DmRiff const* slf, uint32_t id, uint32_t typ); @@ -132,5 +131,5 @@ DMINT void DmRiff_readInt(DmRiff* slf, int32_t* buf); DMINT void DmRiff_readDword(DmRiff* slf, uint32_t* buf); DMINT void DmRiff_readDouble(DmRiff* slf, double* buf); DMINT char const* DmRiff_readString(DmRiff* slf); -DMINT char16_t* DmRiff_readStringUtf(DmRiff* slf); +DMINT uint16_t* DmRiff_readStringUtf(DmRiff* slf); DMINT void DmRiff_reportDone(DmRiff* slf); diff --git a/src/io/Common.c b/src/io/Common.c index 77ad34a..13ec3f3 100644 --- a/src/io/Common.c +++ b/src/io/Common.c @@ -2,14 +2,13 @@ // SPDX-License-Identifier: MIT-Modern-Variant #include "_Internal.h" -#include #include void DmGuid_parse(DmGuid* slf, DmRiff* rif) { DmRiff_read(rif, slf->data, sizeof slf->data); } -char* Dm_utf16ToUtf8Inline(char* out, char16_t const* u16) { +char* Dm_utf16ToUtf8Inline(char* out, uint16_t const* u16) { size_t len = 0; while (u16[len] != 0) { len += 1; @@ -21,13 +20,7 @@ char* Dm_utf16ToUtf8Inline(char* out, char16_t const* u16) { size_t i = 0; size_t j = 0; for (; i < len; ++i) { -#ifndef _WIN32 - j += c16rtomb(out + j, u16[i], &state); -#else - // NOTE: MinGW on Windows does not correctly implement `c16romb`, thus we just use `wcrtomb`. - // According to MinGW, `char16_t` should be equivalent to `wchar_t` on Windows. - j += wcrtomb(out + j, (wchar_t) u16[i], &state); -#endif + j += wcrtomb(out + j, u16[i], &state); } out[j] = '\0'; @@ -38,7 +31,7 @@ void DmUnfo_parse(DmUnfo* slf, DmRiff* rif) { DmRiff cnk; while (DmRiff_readChunk(rif, &cnk)) { if (DmRiff_is(&cnk, DM_FOURCC_UNAM, 0)) { - char16_t* raw = DmRiff_readStringUtf(&cnk); + uint16_t* raw = DmRiff_readStringUtf(&cnk); slf->unam = Dm_utf16ToUtf8Inline((char*) raw, raw); } else { DmRiff_reportDone(&cnk); @@ -83,11 +76,11 @@ void DmReference_parse(DmReference* slf, DmRiff* rif) { } else if (DmRiff_is(&cnk, DM_FOURCC_GUID, 0)) { DmGuid_parse(&slf->guid, &cnk); } else if (DmRiff_is(&cnk, DM_FOURCC_NAME, 0)) { - char16_t* raw = DmRiff_readStringUtf(&cnk); + uint16_t* raw = DmRiff_readStringUtf(&cnk); slf->name = Dm_utf16ToUtf8Inline((char*) raw, raw); continue; // Ignore following bytes } else if (DmRiff_is(&cnk, DM_FOURCC_FILE, 0)) { - char16_t* raw = DmRiff_readStringUtf(&cnk); + uint16_t* raw = DmRiff_readStringUtf(&cnk); slf->file = Dm_utf16ToUtf8Inline((char*) raw, raw); continue; // Ignore following bytes } else if (DmRiff_is(&cnk, DM_FOURCC_VERS, 0)) { diff --git a/src/io/Segment.c b/src/io/Segment.c index 73d6b6c..9704138 100644 --- a/src/io/Segment.c +++ b/src/io/Segment.c @@ -101,8 +101,8 @@ static void DmSegment_parseChordItem(DmMessage_Chord* slf, DmRiff* rif) { { uint32_t end_position = rif->pos + item_size; - char16_t name[16]; - DmRiff_read(rif, name, sizeof name); + uint16_t name[16]; + DmRiff_read(rif, name, 16 * sizeof(int16_t)); (void) Dm_utf16ToUtf8Inline(slf->name, name); DmRiff_readDword(rif, &slf->time);