From 3ccc390155a30532d25301839c0b8b134681d7a5 Mon Sep 17 00:00:00 2001 From: Jamie <146052250+jdennis9@users.noreply.github.com> Date: Sat, 17 May 2025 03:01:23 +1200 Subject: [PATCH] Add file_new and file_new_type wchar variants for C binding (#1271) --- bindings/c/tag_c.cpp | 22 +++++++++++++++++++++- bindings/c/tag_c.h | 6 ++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/bindings/c/tag_c.cpp b/bindings/c/tag_c.cpp index c2d18f0a..473f1f62 100644 --- a/bindings/c/tag_c.cpp +++ b/bindings/c/tag_c.cpp @@ -149,7 +149,15 @@ TagLib_File *taglib_file_new(const char *filename) return reinterpret_cast(new FileRef(filename)); } -TagLib_File *taglib_file_new_type(const char *filename, TagLib_File_Type type) +#ifdef _WIN32 +TagLib_File *taglib_file_new_wchar(const wchar_t *filename) +{ + return reinterpret_cast(new FileRef(filename)); +} +#endif + +template +TagLib_File *taglib_file_new_type_any_char(const T *filename, TagLib_File_Type type) { File *file = NULL; switch(type) { @@ -240,6 +248,18 @@ TagLib_File *taglib_file_new_type(const char *filename, TagLib_File_Type type) return file ? reinterpret_cast(new FileRef(file)) : NULL; } +TagLib_File *taglib_file_new_type(const char *filename, TagLib_File_Type type) +{ + return taglib_file_new_type_any_char(filename, type); +} + +#ifdef _WIN32 +TagLib_File *taglib_file_new_type_wchar(const wchar_t *filename, TagLib_File_Type type) +{ + return taglib_file_new_type_any_char(filename, type); +} +#endif + TagLib_File *taglib_file_new_iostream(TagLib_IOStream *stream) { return reinterpret_cast( diff --git a/bindings/c/tag_c.h b/bindings/c/tag_c.h index fc6b7acc..2513f7f6 100644 --- a/bindings/c/tag_c.h +++ b/bindings/c/tag_c.h @@ -142,12 +142,18 @@ typedef enum { * be opened. */ TAGLIB_C_EXPORT TagLib_File *taglib_file_new(const char *filename); +#ifdef _WIN32 +TAGLIB_C_EXPORT TagLib_File *taglib_file_new_wchar(const wchar_t *filename); +#endif /*! * Creates a TagLib file based on \a filename. Rather than attempting to guess * the type, it will use the one specified by \a type. */ TAGLIB_C_EXPORT TagLib_File *taglib_file_new_type(const char *filename, TagLib_File_Type type); +#ifdef _WIN32 +TAGLIB_C_EXPORT TagLib_File *taglib_file_new_type_wchar(const wchar_t *filename, TagLib_File_Type type); +#endif /*! * Creates a TagLib file from a \a stream.