- tempdir = getenv("TMPDIR");
- if (tempdir == NULL)
- tempdir = TMPDIR;
-
- snprintf(fn, sizeof(fn), "%s/%s.%s.%u%d",
- _config->Find("APT::ExtractTemplates::TempDir", tempdir).c_str(),
- package, prefix, getpid(), i++);
+ std::string tempdir = GetTempDir();
+ snprintf(fn, sizeof(fn), "%s/%s.%s.XXXXXX",
+ _config->Find("APT::ExtractTemplates::TempDir",
+ tempdir.c_str()).c_str(),
+ package, prefix);