+ std::string tempdir = GetTempDir();
+ snprintf(fn, sizeof(fn), "%s/%s.%s.XXXXXX",
+ _config->Find("APT::ExtractTemplates::TempDir",
+ tempdir.c_str()).c_str(),
+ package, prefix);
+ FileFd f;
+ if (data == NULL)
+ data = "";
+ int fd = mkstemp(fn);
+ if (fd < 0) {
+ _error->Errno("ofstream::ofstream",_("Unable to mkstemp %s"),fn);
+ return string();
+ }
+ if (!f.OpenDescriptor(fd, FileFd::WriteOnly, FileFd::None, true))
+ {
+ _error->Errno("ofstream::ofstream",_("Unable to write to %s"),fn);
+ return string();
+ }
+ f.Write(data, strlen(data));
+ f.Close();
+ return fn;