]> granicus.if.org Git - taglib/commitdiff
Fixed initialization of FileStream
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Sun, 19 May 2013 02:09:43 +0000 (11:09 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Sun, 19 May 2013 02:09:43 +0000 (11:09 +0900)
taglib/toolkit/tfile.cpp
taglib/toolkit/tfile.h
taglib/toolkit/tfilestream.cpp
taglib/toolkit/tiostream.cpp

index fdb5237f96cedfdb2c841e1ea7650dfcf0cd99dd..a229e85fa847801af875d0bb1577fb88295517f6 100644 (file)
 #include "tdebug.h"
 #include "tpropertymap.h"
 
-#include <stdio.h>
-#include <string.h>
-#include <sys/stat.h>
-
 #ifdef _WIN32
-# include <wchar.h>
 # include <windows.h>
 # include <io.h>
-# define ftruncate _chsize
 #else
+# include <stdio.h>
 # include <unistd.h>
 #endif
 
-#include <stdlib.h>
-
 #ifndef R_OK
 # define R_OK 4
 #endif
index 30e53f9362680d29a0929b28cca4bd4b0948d8fc..67f6f80f532c9c31da54c80ae1d6bf6ece62850e 100644 (file)
@@ -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;
 
index 7a931cbe7c518a5763a04dcdfa3f0993902811c6..1798134f19ac44dd28a414c8d86357f25aa2c127 100644 (file)
 #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 
@@ -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<const char *>(d->name)));
 # endif 
index b77739752226de49c4163ae1df7b0da1a928a7fe..2832e414b00c4baa320dd7c36143820c5a4efa92 100644 (file)
@@ -29,6 +29,8 @@ using namespace TagLib;
 
 #ifdef _WIN32
 
+# include "tstring.h"
+# include "tdebug.h"
 # include <windows.h>
 
 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;
   }