From 81261dd128567fc3c2bdb5e6db7612f1a9be3bbd Mon Sep 17 00:00:00 2001 From: Scott Wheeler Date: Wed, 20 May 2015 11:53:32 +0200 Subject: [PATCH] This should also work Windows and has less duplicated code --- tests/utils.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/utils.h b/tests/utils.h index 9efe4afc..a935f983 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -27,26 +27,22 @@ inline string testFilePath(const string &filename) inline string copyFile(const string &filename, const string &ext) { + char testFileName[1024]; + #ifdef _WIN32 char *testFileNameBody = tempnam(NULL, NULL); - string testFileName = string(newname_c) + ext; + snprintf(testFileName, sizeof(testFileName), "%s%s", testFileNameBody, ext.c_str()); free(testFileNameBody); - string sourceFileName = testFilePath(filename) + ext; - - CopyFileA(sourceFileName.c_str(), testFileName.c_str(), FALSE); - SetFileAttributesA(testFileName, GetFileAttributesA(testFileName) & ~FILE_ATTRIBUTE_READONLY); - return testFileName; #else - char testFileName[1024]; snprintf(testFileName, sizeof(testFileName), "/%s/taglib-test-XXXXXX%s", P_tmpdir, ext.c_str()); mkstemps(testFileName, 6); - string sourceFileName = testFilePath(filename) + ext; +#endif + string sourceFileName = testFilePath(filename) + ext; ifstream source(sourceFileName, std::ios::binary); ofstream destination(testFileName, std::ios::binary); destination << source.rdbuf(); return string(testFileName); -#endif } inline void deleteFile(const string &filename)