X-Git-Url: https://git.hcoop.net/ntk/apt.git/blobdiff_plain/e7f56293f029505f59670be2bad244f6d9912369..b578738870e83db4e61d6f6591bc73884108b7d4:/cmdline/apt-extracttemplates.cc diff --git a/cmdline/apt-extracttemplates.cc b/cmdline/apt-extracttemplates.cc index 2408a7d9..e4428e05 100644 --- a/cmdline/apt-extracttemplates.cc +++ b/cmdline/apt-extracttemplates.cc @@ -18,8 +18,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -30,14 +30,14 @@ #include #include #include +#include +#include +#include #include #include -#include #include -#include - -#include +#include #include "apt-extracttemplates.h" @@ -137,7 +137,7 @@ bool DebFile::DoItem(Item &I, int &Fd) // DebFile::Process examine element in package and copy /*{{{*/ // --------------------------------------------------------------------- /* */ -bool DebFile::Process(Item &I, const unsigned char *data, +bool DebFile::Process(Item &/*I*/, const unsigned char *data, unsigned long size, unsigned long pos) { switch (Which) @@ -212,7 +212,7 @@ bool DebFile::ParseInfo() // ShowHelp - show a short help text /*{{{*/ // --------------------------------------------------------------------- /* */ -int ShowHelp(void) +static int ShowHelp(void) { ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION, COMMON_ARCH,__DATE__,__TIME__); @@ -237,26 +237,28 @@ int ShowHelp(void) // WriteFile - write the contents of the passed string to a file /*{{{*/ // --------------------------------------------------------------------- /* */ -string WriteFile(const char *package, const char *prefix, const char *data) +static string WriteFile(const char *package, const char *prefix, const char *data) { char fn[512]; - static int i; std::string tempdir = GetTempDir(); - snprintf(fn, sizeof(fn), "%s/%s.%s.%u%d", + snprintf(fn, sizeof(fn), "%s/%s.%s.XXXXXX", _config->Find("APT::ExtractTemplates::TempDir", tempdir.c_str()).c_str(), - package, prefix, getpid(), i++); + package, prefix); FileFd f; if (data == NULL) data = ""; - - if (!f.Open(fn, FileFd::WriteTemp, 0600)) + 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; @@ -265,7 +267,7 @@ string WriteFile(const char *package, const char *prefix, const char *data) // WriteConfig - write out the config data from a debian package file /*{{{*/ // --------------------------------------------------------------------- /* */ -void WriteConfig(const DebFile &file) +static void WriteConfig(const DebFile &file) { string templatefile = WriteFile(file.Package.c_str(), "template", file.Template); string configscript = WriteFile(file.Package.c_str(), "config", file.Config); @@ -279,7 +281,7 @@ void WriteConfig(const DebFile &file) // InitCache - initialize the package cache /*{{{*/ // --------------------------------------------------------------------- /* */ -bool Go(CommandLine &CmdL) +static bool Go(CommandLine &CmdL) { // Initialize the apt cache MMap *Map = 0;