X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/3d8232bf97ce11818fb07813a71136484ea1a44a..99fdd8034b4a5cdb0100a33d0b3d5e26079c1695:/test/libapt/file-helpers.cc?ds=sidebyside diff --git a/test/libapt/file-helpers.cc b/test/libapt/file-helpers.cc index 387192868..48d8a9fbb 100644 --- a/test/libapt/file-helpers.cc +++ b/test/libapt/file-helpers.cc @@ -56,10 +56,17 @@ void helperCreateLink(std::string const &dir, std::string const &targetname, std void helperCreateTemporaryFile(std::string const &id, FileFd &fd, std::string * const filename, char const * const content) { std::string name("apt-test-"); - name.append(id).append(".XXXXXXXX"); + name.append(id); + size_t const giventmp = name.find(".XXXXXX."); + if (giventmp == std::string::npos) + name.append(".XXXXXX"); char * tempfile = strdup(name.c_str()); ASSERT_STRNE(NULL, tempfile); - int tempfile_fd = mkstemp(tempfile); + int tempfile_fd; + if (giventmp == std::string::npos) + tempfile_fd = mkstemp(tempfile); + else + tempfile_fd = mkstemps(tempfile, name.length() - (giventmp + 7)); ASSERT_NE(-1, tempfile_fd); if (filename != NULL) *filename = tempfile; @@ -67,7 +74,7 @@ void helperCreateTemporaryFile(std::string const &id, FileFd &fd, std::string * unlink(tempfile); free(tempfile); - EXPECT_TRUE(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite)); + EXPECT_TRUE(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite, true)); if (content != NULL) { ASSERT_TRUE(fd.Write(content, strlen(content)));