#include "tstring.h"
#include "tdebug.h"
-#include <stdio.h>
-#include <string.h>
-#include <sys/stat.h>
-
#ifdef _WIN32
-# include <wchar.h>
# include <windows.h>
-# include <io.h>
#else
+# include <stdio.h>
# include <unistd.h>
#endif
-#include <stdlib.h>
-
using namespace TagLib;
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)
{
}
}
-#else
+# endif
+
+#else // _WIN32
struct FileNameHandle : public std::string
{
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)
{
}
// 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<const char *>(d->name)));
# endif
#ifdef _WIN32
+# include "tstring.h"
+# include "tdebug.h"
# include <windows.h>
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;
}