--- taglib-1.4\taglib\toolkit\tfile.cpp 2005-07-26 00:16:32.000000000 +0200 +++ taglib\taglib\toolkit\tfile.cpp 2006-01-20 22:33:55.250000000 +0100 @@ -25,8 +25,23 @@ #include #include -#include +#ifdef _WIN32 +# include +# ifdef _MSC_VER +# include +# define F_OK 0 +# define X_OK 1 +# define W_OK 2 +# define R_OK 4 +# else +# include +# endif +# define ftruncate(a,b) chsize(a,b) +#else +# include +#endif + using namespace TagLib; class File::FilePrivate @@ -57,12 +72,67 @@ // public members //////////////////////////////////////////////////////////////////////////////// +#ifdef _WIN32 + +LPSTR toANSI(const char *file) +{ + int size = strlen(file) + 1; + LPWSTR lpWideCharStr = new WCHAR[size]; + if(lpWideCharStr) { + if(MultiByteToWideChar(CP_UTF8, 0, file, -1, lpWideCharStr, size) > 0) { + LPSTR lpAnsiCharStr = new CHAR[size]; + if(lpAnsiCharStr) { + if(WideCharToMultiByte(CP_ACP, 0, lpWideCharStr, -1, lpAnsiCharStr, size, NULL, NULL) > 0) { + delete [] lpWideCharStr; + return lpAnsiCharStr; + } + delete [] lpAnsiCharStr; + } + } + delete [] lpWideCharStr; + } + return NULL; +} + +LPWSTR toUTF16(const char *file) +{ + int size = strlen(file) + 5; + LPWSTR lpWideCharStr = new WCHAR[size]; + if (lpWideCharStr) { + wcscpy(lpWideCharStr, L"\\\\?\\"); + if (MultiByteToWideChar(CP_UTF8, 0, file, -1, lpWideCharStr + 4, size) > 0) { + return lpWideCharStr; + } + delete [] lpWideCharStr; + } + return NULL; +} + +#endif + File::File(const char *file) { d = new FilePrivate(::strdup(file)); d->readOnly = !isWritable(file); +#ifdef _WIN32 + if(GetVersion() < 0x80000000) { + LPWSTR nfile = toUTF16(file); + if(nfile) { + d->file = _wfopen(nfile, d->readOnly ? L"rb" : L"r+b"); + delete [] nfile; + } + } + else { + LPSTR nfile = toANSI(file); + if(nfile) { + d->file = fopen(nfile, d->readOnly ? "rb" : "r+b"); + delete [] nfile; + } + } +#else d->file = fopen(file, d->readOnly ? "r" : "r+"); +#endif if(!d->file) debug("Could not open file " + String(file)); @@ -409,7 +479,26 @@ bool File::isReadable(const char *file) { +#ifdef _WIN32 + int ret = 1; + if(GetVersion() < 0x80000000) { + LPWSTR nfile = toUTF16(file); + if(nfile) { + ret = _waccess(nfile, R_OK); + delete [] nfile; + } + } + else { + LPSTR nfile = toANSI(file); + if(nfile) { + ret = access(nfile, R_OK); + delete [] nfile; + } + } + return ret == 0; +#else return access(file, R_OK) == 0; +#endif } bool File::isOpen() const @@ -475,7 +564,26 @@ bool File::isWritable(const char *file) { +#ifdef _WIN32 + int ret = 1; + if(GetVersion() < 0x80000000) { + LPWSTR nfile = toUTF16(file); + if(nfile) { + ret = _waccess(nfile, W_OK); + delete [] nfile; + } + } + else { + LPSTR nfile = toANSI(file); + if(nfile) { + ret = access(nfile, W_OK); + delete [] nfile; + } + } + return ret == 0; +#else return access(file, W_OK) == 0; +#endif } //////////////////////////////////////////////////////////////////////////////// --- taglib-1.4/config.h 1970-01-01 01:00:00.000000000 +0100 +++ taglib/config.h 2006-01-19 16:46:01.843750000 +0100 @@ -0,0 +1,64 @@ +/* config.h.in. Generated from configure.in by autoheader. */ + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* C++ compiler supports template repository */ +#define HAVE_TEMPLATE_REPOSITORY 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* have zlib */ +#define HAVE_ZLIB 1 + +/* Suffix for lib directories */ +#undef KDELIBSUFF + +/* Name of package */ +#define PACKAGE "taglib" + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#undef VERSION