diff --git a/taglib/toolkit/tfile.cpp b/taglib/toolkit/tfile.cpp index fdb5237f..a229e85f 100644 --- a/taglib/toolkit/tfile.cpp +++ b/taglib/toolkit/tfile.cpp @@ -29,21 +29,14 @@ #include "tdebug.h" #include "tpropertymap.h" -#include -#include -#include - #ifdef _WIN32 -# include # include # include -# define ftruncate _chsize #else +# include # include #endif -#include - #ifndef R_OK # define R_OK 4 #endif diff --git a/taglib/toolkit/tfile.h b/taglib/toolkit/tfile.h index 30e53f93..67f6f80f 100644 --- a/taglib/toolkit/tfile.h +++ b/taglib/toolkit/tfile.h @@ -213,7 +213,7 @@ namespace TagLib { bool isOpen() const; /*! - * Returns true if the file is open and readble. + * Returns true if the file is open and readable. */ bool isValid() const; diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index 7a931cbe..1798134f 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -27,20 +27,13 @@ #include "tstring.h" #include "tdebug.h" -#include -#include -#include - #ifdef _WIN32 -# include # include -# include #else +# include # include #endif -#include - using namespace TagLib; namespace @@ -89,11 +82,12 @@ namespace return 0; } +# ifndef NDEBUG + // Convert a string in a local encoding into a UTF-16 string. - // This function should only be used to generate an error message. - // In actual use, file names in local encodings are passed to CreateFileA() - // without any conversions. + // Debugging use only. In actual use, file names in local encodings are passed to + // CreateFileA() without any conversions. String fileNameToString(const FileName &name) { @@ -115,7 +109,9 @@ namespace } } -#else +# endif + +#else // _WIN32 struct FileNameHandle : public std::string { @@ -146,16 +142,16 @@ namespace return fwrite(buffer.data(), sizeof(char), buffer.size(), file); } -#endif +#endif // _WIN32 } class FileStream::FileStreamPrivate { public: - FileStreamPrivate(const FileName &fileName, bool openReadOnly) + FileStreamPrivate(const FileName &fileName) : file(InvalidFileHandle) , name(fileName) - , readOnly(openReadOnly) + , readOnly(true) , size(0) { } @@ -172,23 +168,23 @@ public: // public members //////////////////////////////////////////////////////////////////////////////// -FileStream::FileStream(FileName file, bool openReadOnly) - : d(new FileStreamPrivate(file, openReadOnly)) +FileStream::FileStream(FileName fileName, bool openReadOnly) + : d(new FileStreamPrivate(fileName)) { // First try with read / write mode, if that fails, fall back to read only. if(!openReadOnly) - d->file = openFile(file, false); + d->file = openFile(fileName, false); if(d->file != InvalidFileHandle) d->readOnly = false; else - d->file = openFile(d->name, true); + d->file = openFile(fileName, true); if(d->file == InvalidFileHandle) { # ifdef _WIN32 - debug("Could not open file " + fileNameToString(d->name)); + debug("Could not open file " + fileNameToString(fileName)); # else debug("Could not open file " + String(static_cast(d->name))); # endif diff --git a/taglib/toolkit/tiostream.cpp b/taglib/toolkit/tiostream.cpp index b7773975..2832e414 100644 --- a/taglib/toolkit/tiostream.cpp +++ b/taglib/toolkit/tiostream.cpp @@ -29,6 +29,8 @@ using namespace TagLib; #ifdef _WIN32 +# include "tstring.h" +# include "tdebug.h" # include namespace @@ -50,14 +52,18 @@ namespace // This function should only be used in Windows9x systems which don't support // Unicode file names. - std::string unicodeToAnsi(const std::wstring &wstr) + std::string unicodeToAnsi(const wchar_t *wstr) { - const int len = WideCharToMultiByte(CP_ACP, 0, &wstr[0], -1, NULL, 0, NULL, NULL); + if(SystemSupportsUnicode) { + debug("unicodeToAnsi() - Should not be used on WinNT systems."); + } + + const int len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL); if(len == 0) return std::string(); std::string str(len, '\0'); - WideCharToMultiByte(CP_ACP, 0, &wstr[0], -1, &str[0], len, NULL, NULL); + WideCharToMultiByte(CP_ACP, 0, wstr, -1, &str[0], len, NULL, NULL); return str; }