summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/cdromutl.cc90
-rw-r--r--apt-pkg/contrib/cmndline.cc5
-rw-r--r--apt-pkg/contrib/cmndline.h8
-rw-r--r--apt-pkg/contrib/configuration.cc28
-rw-r--r--apt-pkg/contrib/configuration.h16
-rw-r--r--apt-pkg/contrib/crc-16.h4
-rw-r--r--apt-pkg/contrib/error.cc6
-rw-r--r--apt-pkg/contrib/error.h37
-rw-r--r--apt-pkg/contrib/fileutl.cc475
-rw-r--r--apt-pkg/contrib/fileutl.h11
-rw-r--r--apt-pkg/contrib/gpgv.cc18
-rw-r--r--apt-pkg/contrib/gpgv.h18
-rw-r--r--apt-pkg/contrib/hashes.cc8
-rw-r--r--apt-pkg/contrib/hashes.h17
-rw-r--r--apt-pkg/contrib/hashsum.cc3
-rw-r--r--apt-pkg/contrib/hashsum_template.h52
-rw-r--r--apt-pkg/contrib/macros.h84
-rw-r--r--apt-pkg/contrib/md5.cc6
-rw-r--r--apt-pkg/contrib/md5.h9
-rw-r--r--apt-pkg/contrib/mmap.cc6
-rw-r--r--apt-pkg/contrib/netrc.cc5
-rw-r--r--apt-pkg/contrib/netrc.h6
-rw-r--r--apt-pkg/contrib/progress.cc14
-rw-r--r--apt-pkg/contrib/sha1.cc5
-rw-r--r--apt-pkg/contrib/sha1.h7
-rw-r--r--apt-pkg/contrib/sha2.h10
-rw-r--r--apt-pkg/contrib/sha2_internal.cc1
-rw-r--r--apt-pkg/contrib/sha2_internal.h1
-rw-r--r--apt-pkg/contrib/strutl.cc17
-rw-r--r--apt-pkg/contrib/strutl.h75
30 files changed, 680 insertions, 362 deletions
diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc
index 20210ec0a..936e377fb 100644
--- a/apt-pkg/contrib/cdromutl.cc
+++ b/apt-pkg/contrib/cdromutl.cc
@@ -19,7 +19,11 @@
#include <apt-pkg/configuration.h>
#include <apt-pkg/strutl.h>
-#include <sys/wait.h>
+#include <stdlib.h>
+#include <string.h>
+#include <iostream>
+#include <string>
+#include <vector>
#include <sys/statvfs.h>
#include <dirent.h>
#include <fcntl.h>
@@ -42,11 +46,16 @@ bool IsMounted(string &Path)
{
if (Path.empty() == true)
return false;
-
+
// Need that trailing slash for directories
if (Path[Path.length() - 1] != '/')
Path += '/';
-
+
+ // if the path has a ".disk" directory we treat it as mounted
+ // this way even extracted copies of disks are recognized
+ if (DirectoryExists(Path + ".disk/") == true)
+ return true;
+
/* First we check if the path is actually mounted, we do this by
stating the path and the previous directory (careful of links!)
and comparing their device fields. */
@@ -66,7 +75,13 @@ bool IsMounted(string &Path)
leave /etc/mtab inconsitant. We drop all messages this produces. */
bool UnmountCdrom(string Path)
{
- if (IsMounted(Path) == false)
+ // do not generate errors, even if the mountpoint does not exist
+ // the mountpoint might be auto-created by the mount command
+ // and a non-existing mountpoint is surely not mounted
+ _error->PushToStack();
+ bool const mounted = IsMounted(Path);
+ _error->RevertToStack();
+ if (mounted == false)
return true;
for (int i=0;i<3;i++)
@@ -78,8 +93,9 @@ bool UnmountCdrom(string Path)
if (Child == 0)
{
// Make all the fds /dev/null
- for (int I = 0; I != 3; I++)
- dup2(open("/dev/null",O_RDWR),I);
+ int const null_fd = open("/dev/null",O_RDWR);
+ for (int I = 0; I != 3; ++I)
+ dup2(null_fd, I);
if (_config->Exists("Acquire::cdrom::"+Path+"::UMount") == true)
{
@@ -113,19 +129,24 @@ bool UnmountCdrom(string Path)
/* We fork mount and drop all messages */
bool MountCdrom(string Path, string DeviceName)
{
- if (IsMounted(Path) == true)
+ // do not generate errors, even if the mountpoint does not exist
+ // the mountpoint might be auto-created by the mount command
+ _error->PushToStack();
+ bool const mounted = IsMounted(Path);
+ _error->RevertToStack();
+ if (mounted == true)
return true;
-
+
int Child = ExecFork();
// The child
if (Child == 0)
{
// Make all the fds /dev/null
- int null_fd = open("/dev/null",O_RDWR);
- for (int I = 0; I != 3; I++)
+ int const null_fd = open("/dev/null",O_RDWR);
+ for (int I = 0; I != 3; ++I)
dup2(null_fd, I);
-
+
if (_config->Exists("Acquire::cdrom::"+Path+"::Mount") == true)
{
if (system(_config->Find("Acquire::cdrom::"+Path+"::Mount").c_str()) != 0)
@@ -242,37 +263,34 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version)
return true;
}
/*}}}*/
-
// FindMountPointForDevice - Find mountpoint for the given device /*{{{*/
string FindMountPointForDevice(const char *devnode)
{
- char buf[255];
- char *out[10];
- int i=0;
-
// this is the order that mount uses as well
- const char *mount[] = { "/etc/mtab",
- "/proc/mount",
- NULL };
+ std::vector<std::string> const mounts = _config->FindVector("Dir::state::MountPoints", "/etc/mtab,/proc/mount");
- for (i=0; mount[i] != NULL; i++) {
- if (FileExists(mount[i])) {
- FILE *f=fopen(mount[i], "r");
- while ( fgets(buf, sizeof(buf), f) != NULL) {
- if (strncmp(buf, devnode, strlen(devnode)) == 0) {
- if(TokSplitString(' ', buf, out, 10))
- {
- fclose(f);
- // unescape the \0XXX chars in the path
- string mount_point = out[1];
- return DeEscapeString(mount_point);
- }
- }
- }
- fclose(f);
+ for (std::vector<std::string>::const_iterator m = mounts.begin(); m != mounts.end(); ++m)
+ if (FileExists(*m) == true)
+ {
+ char * line = NULL;
+ size_t line_len = 0;
+ FILE * f = fopen(m->c_str(), "r");
+ while(getline(&line, &line_len, f) != -1)
+ {
+ char * out[] = { NULL, NULL, NULL };
+ TokSplitString(' ', line, out, 3);
+ if (out[2] != NULL || out[1] == NULL || out[0] == NULL)
+ continue;
+ if (strcmp(out[0], devnode) != 0)
+ continue;
+ fclose(f);
+ // unescape the \0XXX chars in the path
+ string mount_point = out[1];
+ return DeEscapeString(mount_point);
+ }
+ fclose(f);
}
- }
-
+
return string();
}
/*}}}*/
diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc
index ed5800007..3799c822d 100644
--- a/apt-pkg/contrib/cmndline.cc
+++ b/apt-pkg/contrib/cmndline.cc
@@ -18,6 +18,11 @@
#include <apt-pkg/error.h>
#include <apt-pkg/strutl.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <string>
+
#include <apti18n.h>
/*}}}*/
using namespace std;
diff --git a/apt-pkg/contrib/cmndline.h b/apt-pkg/contrib/cmndline.h
index 180276633..143df58b2 100644
--- a/apt-pkg/contrib/cmndline.h
+++ b/apt-pkg/contrib/cmndline.h
@@ -44,6 +44,8 @@
#ifndef PKGLIB_CMNDLINE_H
#define PKGLIB_CMNDLINE_H
+#include <apt-pkg/macros.h>
+
#ifndef APT_8_CLEANER_HEADERS
#include <apt-pkg/configuration.h>
#endif
@@ -80,14 +82,14 @@ class CommandLine
bool Parse(int argc,const char **argv);
void ShowHelp();
- unsigned int FileSize() const;
+ unsigned int FileSize() const APT_PURE;
bool DispatchArg(Dispatch *List,bool NoMatch = true);
static char const * GetCommand(Dispatch const * const Map,
- unsigned int const argc, char const * const * const argv);
+ unsigned int const argc, char const * const * const argv) APT_PURE;
static CommandLine::Args MakeArgs(char ShortOpt, char const *LongOpt,
- char const *ConfName, unsigned long Flags);
+ char const *ConfName, unsigned long Flags) APT_CONST;
CommandLine(Args *AList,Configuration *Conf);
~CommandLine();
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index 4ef4663c0..00f6ad0f9 100644
--- a/apt-pkg/contrib/configuration.cc
+++ b/apt-pkg/contrib/configuration.cc
@@ -21,10 +21,18 @@
#include <apt-pkg/error.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/fileutl.h>
-
+#include <apt-pkg/macros.h>
+
+#include <ctype.h>
+#include <regex.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <algorithm>
+#include <string>
#include <vector>
#include <fstream>
-#include <iostream>
#include <apti18n.h>
@@ -42,8 +50,7 @@ Configuration::Configuration() : ToFree(true)
}
Configuration::Configuration(const Item *Root) : Root((Item *)Root), ToFree(false)
{
-};
-
+}
/*}}}*/
// Configuration::~Configuration - Destructor /*{{{*/
// ---------------------------------------------------------------------
@@ -246,12 +253,18 @@ string Configuration::FindDir(const char *Name,const char *Default) const
// Configuration::FindVector - Find a vector of values /*{{{*/
// ---------------------------------------------------------------------
/* Returns a vector of config values under the given item */
-vector<string> Configuration::FindVector(const char *Name) const
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR < 13)
+vector<string> Configuration::FindVector(const char *Name) const { return FindVector(Name, ""); }
+#endif
+vector<string> Configuration::FindVector(const char *Name, std::string const &Default) const
{
vector<string> Vec;
const Item *Top = Lookup(Name);
if (Top == NULL)
- return Vec;
+ return VectorizeString(Default, ',');
+
+ if (Top->Value.empty() == false)
+ return VectorizeString(Top->Value, ',');
Item *I = Top->Child;
while(I != NULL)
@@ -259,6 +272,9 @@ vector<string> Configuration::FindVector(const char *Name) const
Vec.push_back(I->Value);
I = I->Next;
}
+ if (Vec.empty() == true)
+ return VectorizeString(Default, ',');
+
return Vec;
}
/*}}}*/
diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h
index 8e09ea0a6..c256139f4 100644
--- a/apt-pkg/contrib/configuration.h
+++ b/apt-pkg/contrib/configuration.h
@@ -74,8 +74,22 @@ class Configuration
std::string Find(std::string const &Name, std::string const &Default) const {return Find(Name.c_str(),Default.c_str());};
std::string FindFile(const char *Name,const char *Default = 0) const;
std::string FindDir(const char *Name,const char *Default = 0) const;
+ /** return a list of child options
+ *
+ * Options like Acquire::Languages are handled as lists which
+ * can be overridden and have a default. For the later two a comma
+ * separated list of values is supported.
+ *
+ * \param Name of the parent node
+ * \param Default list of values separated by commas */
+ std::vector<std::string> FindVector(const char *Name, std::string const &Default) const;
+ std::vector<std::string> FindVector(std::string const &Name, std::string const &Default) const { return FindVector(Name.c_str(), Default); };
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+ std::vector<std::string> FindVector(const char *Name) const { return FindVector(Name, ""); };
+#else
std::vector<std::string> FindVector(const char *Name) const;
- std::vector<std::string> FindVector(std::string const &Name) const { return FindVector(Name.c_str()); };
+#endif
+ std::vector<std::string> FindVector(std::string const &Name) const { return FindVector(Name.c_str(), ""); };
int FindI(const char *Name,int const &Default = 0) const;
int FindI(std::string const &Name,int const &Default = 0) const {return FindI(Name.c_str(),Default);};
bool FindB(const char *Name,bool const &Default = false) const;
diff --git a/apt-pkg/contrib/crc-16.h b/apt-pkg/contrib/crc-16.h
index 702de40b2..08acdafb7 100644
--- a/apt-pkg/contrib/crc-16.h
+++ b/apt-pkg/contrib/crc-16.h
@@ -10,8 +10,10 @@
#ifndef APTPKG_CRC16_H
#define APTPKG_CRC16_H
+#include <apt-pkg/macros.h>
+
#define INIT_FCS 0xffff
unsigned short AddCRC16(unsigned short fcs, void const *buf,
- unsigned long long len);
+ unsigned long long len) APT_PURE;
#endif
diff --git a/apt-pkg/contrib/error.cc b/apt-pkg/contrib/error.cc
index d457781c3..892cd4874 100644
--- a/apt-pkg/contrib/error.cc
+++ b/apt-pkg/contrib/error.cc
@@ -17,12 +17,14 @@
#include <apt-pkg/error.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <list>
#include <iostream>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
#include <string>
#include <cstring>
@@ -223,7 +225,7 @@ void GlobalError::DumpErrors(std::ostream &out, MsgType const &threshold,
void GlobalError::Discard() {
Messages.clear();
PendingFlag = false;
-};
+}
/*}}}*/
// GlobalError::empty - does our error list include anything? /*{{{*/
bool GlobalError::empty(MsgType const &trashhold) const {
diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h
index bcee70b1a..ed8c19153 100644
--- a/apt-pkg/contrib/error.h
+++ b/apt-pkg/contrib/error.h
@@ -46,6 +46,7 @@
#include <list>
#include <string>
+#include <stddef.h>
#include <stdarg.h>
class GlobalError /*{{{*/
@@ -73,7 +74,7 @@ public: /*{{{*/
*
* \return \b false
*/
- bool FatalE(const char *Function,const char *Description,...) __like_printf(3) __cold;
+ bool FatalE(const char *Function,const char *Description,...) APT_PRINTF(3) APT_COLD;
/** \brief add an Error message with errno to the list
*
@@ -82,7 +83,7 @@ public: /*{{{*/
*
* \return \b false
*/
- bool Errno(const char *Function,const char *Description,...) __like_printf(3) __cold;
+ bool Errno(const char *Function,const char *Description,...) APT_PRINTF(3) APT_COLD;
/** \brief add a warning message with errno to the list
*
@@ -94,7 +95,7 @@ public: /*{{{*/
*
* \return \b false
*/
- bool WarningE(const char *Function,const char *Description,...) __like_printf(3) __cold;
+ bool WarningE(const char *Function,const char *Description,...) APT_PRINTF(3) APT_COLD;
/** \brief add a notice message with errno to the list
*
@@ -103,7 +104,7 @@ public: /*{{{*/
*
* \return \b false
*/
- bool NoticeE(const char *Function,const char *Description,...) __like_printf(3) __cold;
+ bool NoticeE(const char *Function,const char *Description,...) APT_PRINTF(3) APT_COLD;
/** \brief add a debug message with errno to the list
*
@@ -112,7 +113,7 @@ public: /*{{{*/
*
* \return \b false
*/
- bool DebugE(const char *Function,const char *Description,...) __like_printf(3) __cold;
+ bool DebugE(const char *Function,const char *Description,...) APT_PRINTF(3) APT_COLD;
/** \brief adds an errno message with the given type
*
@@ -121,7 +122,7 @@ public: /*{{{*/
* \param Description of the error
*/
bool InsertErrno(MsgType const &type, const char* Function,
- const char* Description,...) __like_printf(4) __cold;
+ const char* Description,...) APT_PRINTF(4) APT_COLD;
/** \brief adds an errno message with the given type
*
@@ -140,7 +141,7 @@ public: /*{{{*/
*/
bool InsertErrno(MsgType type, const char* Function,
const char* Description, va_list &args,
- int const errsv, size_t &msgSize);
+ int const errsv, size_t &msgSize) APT_COLD;
/** \brief add an fatal error message to the list
*
@@ -155,7 +156,7 @@ public: /*{{{*/
*
* \return \b false
*/
- bool Fatal(const char *Description,...) __like_printf(2) __cold;
+ bool Fatal(const char *Description,...) APT_PRINTF(2) APT_COLD;
/** \brief add an Error message to the list
*
@@ -163,7 +164,7 @@ public: /*{{{*/
*
* \return \b false
*/
- bool Error(const char *Description,...) __like_printf(2) __cold;
+ bool Error(const char *Description,...) APT_PRINTF(2) APT_COLD;
/** \brief add a warning message to the list
*
@@ -174,7 +175,7 @@ public: /*{{{*/
*
* \return \b false
*/
- bool Warning(const char *Description,...) __like_printf(2) __cold;
+ bool Warning(const char *Description,...) APT_PRINTF(2) APT_COLD;
/** \brief add a notice message to the list
*
@@ -187,7 +188,7 @@ public: /*{{{*/
*
* \return \b false
*/
- bool Notice(const char *Description,...) __like_printf(2) __cold;
+ bool Notice(const char *Description,...) APT_PRINTF(2) APT_COLD;
/** \brief add a debug message to the list
*
@@ -195,14 +196,14 @@ public: /*{{{*/
*
* \return \b false
*/
- bool Debug(const char *Description,...) __like_printf(2) __cold;
+ bool Debug(const char *Description,...) APT_PRINTF(2) APT_COLD;
/** \brief adds an error message with the given type
*
* \param type of the error message
* \param Description of the error
*/
- bool Insert(MsgType const &type, const char* Description,...) __like_printf(3) __cold;
+ bool Insert(MsgType const &type, const char* Description,...) APT_PRINTF(3) APT_COLD;
/** \brief adds an error message with the given type
*
@@ -218,13 +219,13 @@ public: /*{{{*/
* should call this method again in that case
*/
bool Insert(MsgType type, const char* Description,
- va_list &args, size_t &msgSize) __cold;
+ va_list &args, size_t &msgSize) APT_COLD;
/** \brief is an error in the list?
*
* \return \b true if an error is included in the list, \b false otherwise
*/
- inline bool PendingError() const {return PendingFlag;};
+ inline bool PendingError() const APT_PURE {return PendingFlag;};
/** \brief is the list empty?
*
@@ -232,11 +233,11 @@ public: /*{{{*/
* if you want to check if also no notices happened set the parameter
* flag to \b false.
*
- * \param WithoutNotice does notices count, default is \b true, so no
+ * \param threshold minimim level considered
*
* \return \b true if an the list is empty, \b false otherwise
*/
- bool empty(MsgType const &trashhold = WARNING) const;
+ bool empty(MsgType const &threshold = WARNING) const APT_PURE;
/** \brief returns and removes the first (or last) message in the list
*
@@ -302,7 +303,7 @@ public: /*{{{*/
void MergeWithStack();
/** \brief return the deep of the stack */
- size_t StackCount() const {
+ size_t StackCount() const APT_PURE {
return Stacks.size();
}
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 79bcf112c..1eabf37f4 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -1,6 +1,5 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: fileutl.cc,v 1.42 2002/09/14 05:29:22 jgg Exp $
/* ######################################################################
File Utilities
@@ -26,16 +25,22 @@
#include <apt-pkg/sptr.h>
#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/configuration.h>
-
+#include <apt-pkg/macros.h>
+
+#include <ctype.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <sys/select.h>
+#include <time.h>
+#include <string>
+#include <vector>
#include <cstdlib>
#include <cstring>
#include <cstdio>
-
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
-#include <sys/types.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <dirent.h>
@@ -52,6 +57,10 @@
#ifdef HAVE_BZ2
#include <bzlib.h>
#endif
+#ifdef HAVE_LZMA
+ #include <stdint.h>
+ #include <lzma.h>
+#endif
#ifdef WORDS_BIGENDIAN
#include <inttypes.h>
@@ -62,54 +71,6 @@
using namespace std;
-class FileFdPrivate {
- public:
-#ifdef HAVE_ZLIB
- gzFile gz;
-#else
- void* gz;
-#endif
-#ifdef HAVE_BZ2
- BZFILE* bz2;
-#else
- void* bz2;
-#endif
- int compressed_fd;
- pid_t compressor_pid;
- bool pipe;
- APT::Configuration::Compressor compressor;
- unsigned int openmode;
- unsigned long long seekpos;
- FileFdPrivate() : gz(NULL), bz2(NULL),
- compressed_fd(-1), compressor_pid(-1), pipe(false),
- openmode(0), seekpos(0) {};
- bool CloseDown(std::string const &FileName)
- {
- bool Res = true;
-#ifdef HAVE_ZLIB
- if (gz != NULL) {
- int const e = gzclose(gz);
- gz = NULL;
- // gzdclose() on empty files always fails with "buffer error" here, ignore that
- if (e != 0 && e != Z_BUF_ERROR)
- Res &= _error->Errno("close",_("Problem closing the gzip file %s"), FileName.c_str());
- }
-#endif
-#ifdef HAVE_BZ2
- if (bz2 != NULL) {
- BZ2_bzclose(bz2);
- bz2 = NULL;
- }
-#endif
- if (compressor_pid > 0)
- ExecWait(compressor_pid, "FileFdCompressor", true);
- compressor_pid = -1;
-
- return Res;
- }
- ~FileFdPrivate() { CloseDown(""); }
-};
-
// RunScripts - Run a set of scripts from a configuration subtree /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -874,6 +835,122 @@ bool ExecWait(pid_t Pid,const char *Name,bool Reap)
}
/*}}}*/
+class FileFdPrivate { /*{{{*/
+ public:
+#ifdef HAVE_ZLIB
+ gzFile gz;
+#endif
+#ifdef HAVE_BZ2
+ BZFILE* bz2;
+#endif
+#ifdef HAVE_LZMA
+ struct LZMAFILE {
+ FILE* file;
+ uint8_t buffer[4096];
+ lzma_stream stream;
+ lzma_ret err;
+ bool eof;
+ bool compressing;
+
+ LZMAFILE() : file(NULL), eof(false), compressing(false) {}
+ ~LZMAFILE() {
+ if (compressing == true)
+ {
+ for (;;) {
+ stream.avail_out = sizeof(buffer)/sizeof(buffer[0]);
+ stream.next_out = buffer;
+ err = lzma_code(&stream, LZMA_FINISH);
+ if (err != LZMA_OK && err != LZMA_STREAM_END)
+ {
+ _error->Error("~LZMAFILE: Compress finalisation failed");
+ break;
+ }
+ size_t const n = sizeof(buffer)/sizeof(buffer[0]) - stream.avail_out;
+ if (n && fwrite(buffer, 1, n, file) != n)
+ {
+ _error->Errno("~LZMAFILE",_("Write error"));
+ break;
+ }
+ if (err == LZMA_STREAM_END)
+ break;
+ }
+ }
+ lzma_end(&stream);
+ fclose(file);
+ }
+ };
+ LZMAFILE* lzma;
+#endif
+ int compressed_fd;
+ pid_t compressor_pid;
+ bool pipe;
+ APT::Configuration::Compressor compressor;
+ unsigned int openmode;
+ unsigned long long seekpos;
+ FileFdPrivate() :
+#ifdef HAVE_ZLIB
+ gz(NULL),
+#endif
+#ifdef HAVE_BZ2
+ bz2(NULL),
+#endif
+#ifdef HAVE_LZMA
+ lzma(NULL),
+#endif
+ compressed_fd(-1), compressor_pid(-1), pipe(false),
+ openmode(0), seekpos(0) {};
+ bool InternalClose(std::string const &FileName)
+ {
+ if (false)
+ /* dummy so that the rest can be 'else if's */;
+#ifdef HAVE_ZLIB
+ else if (gz != NULL) {
+ int const e = gzclose(gz);
+ gz = NULL;
+ // gzdclose() on empty files always fails with "buffer error" here, ignore that
+ if (e != 0 && e != Z_BUF_ERROR)
+ return _error->Errno("close",_("Problem closing the gzip file %s"), FileName.c_str());
+ }
+#endif
+#ifdef HAVE_BZ2
+ else if (bz2 != NULL) {
+ BZ2_bzclose(bz2);
+ bz2 = NULL;
+ }
+#endif
+#ifdef HAVE_LZMA
+ else if (lzma != NULL) {
+ delete lzma;
+ lzma = NULL;
+ }
+#endif
+ return true;
+ }
+ bool CloseDown(std::string const &FileName)
+ {
+ bool const Res = InternalClose(FileName);
+
+ if (compressor_pid > 0)
+ ExecWait(compressor_pid, "FileFdCompressor", true);
+ compressor_pid = -1;
+
+ return Res;
+ }
+ bool InternalStream() const {
+ return false
+#ifdef HAVE_BZ2
+ || bz2 != NULL
+#endif
+#ifdef HAVE_LZMA
+ || lzma != NULL
+#endif
+ ;
+ }
+
+
+ ~FileFdPrivate() { CloseDown(""); }
+};
+ /*}}}*/
// FileFd::Open - Open a file /*{{{*/
// ---------------------------------------------------------------------
/* The most commonly used open mode combinations are given with Mode */
@@ -891,7 +968,7 @@ bool FileFd::Open(string FileName,unsigned int const Mode,CompressMode Compress,
{
for (; compressor != compressors.end(); ++compressor)
{
- std::string file = std::string(FileName).append(compressor->Extension);
+ std::string file = FileName + compressor->Extension;
if (FileExists(file) == false)
continue;
FileName = file;
@@ -1061,30 +1138,12 @@ bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration:
{
Close();
Flags = (AutoClose) ? FileFd::AutoClose : 0;
- if (AutoClose == false && (
-#ifdef HAVE_ZLIB
- compressor.Name == "gzip" ||
-#endif
-#ifdef HAVE_BZ2
- compressor.Name == "bzip2" ||
-#endif
- false))
- {
- // Need to duplicate fd here or gzclose for cleanup will close the fd as well
- iFd = dup(Fd);
- }
- else
- iFd = Fd;
+ iFd = Fd;
this->FileName = "";
- if (Fd == -1 || OpenInternDescriptor(Mode, compressor) == false)
+ if (OpenInternDescriptor(Mode, compressor) == false)
{
if (iFd != -1 && (
-#ifdef HAVE_ZLIB
- compressor.Name == "gzip" ||
-#endif
-#ifdef HAVE_BZ2
- compressor.Name == "bzip2" ||
-#endif
+ (Flags & Compressed) == Compressed ||
AutoClose == true))
{
close (iFd);
@@ -1096,52 +1155,121 @@ bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration:
}
bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor)
{
+ if (iFd == -1)
+ return false;
if (compressor.Name == "." || compressor.Binary.empty() == true)
return true;
+#if defined HAVE_ZLIB || defined HAVE_BZ2 || defined HAVE_LZMA
+ // the API to open files is similar, so setup to avoid code duplicates later
+ // and while at it ensure that we close before opening (if its a reopen)
+ void* (*compress_open)(int, const char *) = NULL;
+ if (false)
+ /* dummy so that the rest can be 'else if's */;
+#define APT_COMPRESS_INIT(NAME,OPEN) \
+ else if (compressor.Name == NAME) \
+ { \
+ compress_open = (void*(*)(int, const char *)) OPEN; \
+ if (d != NULL) d->InternalClose(FileName); \
+ }
+#ifdef HAVE_ZLIB
+ APT_COMPRESS_INIT("gzip", gzdopen)
+#endif
+#ifdef HAVE_BZ2
+ APT_COMPRESS_INIT("bzip2", BZ2_bzdopen)
+#endif
+#ifdef HAVE_LZMA
+ APT_COMPRESS_INIT("xz", fdopen)
+ APT_COMPRESS_INIT("lzma", fdopen)
+#endif
+#undef APT_COMPRESS_INIT
+#endif
+
if (d == NULL)
{
d = new FileFdPrivate();
d->openmode = Mode;
d->compressor = compressor;
+#if defined HAVE_ZLIB || defined HAVE_BZ2 || defined HAVE_LZMA
+ if (AutoClose == false && compress_open != NULL)
+ {
+ // Need to duplicate fd here or gz/bz2 close for cleanup will close the fd as well
+ int const internFd = dup(iFd);
+ if (internFd == -1)
+ return FileFdErrno("OpenInternDescriptor", _("Could not open file descriptor %d"), iFd);
+ iFd = internFd;
+ }
+#endif
}
-#ifdef HAVE_ZLIB
- if (compressor.Name == "gzip")
+#if defined HAVE_ZLIB || defined HAVE_BZ2 || defined HAVE_LZMA
+ if (compress_open != NULL)
{
- if (d->gz != NULL)
- {
- gzclose(d->gz);
- d->gz = NULL;
- }
+ void* compress_struct = NULL;
if ((Mode & ReadWrite) == ReadWrite)
- d->gz = gzdopen(iFd, "r+");
+ compress_struct = compress_open(iFd, "r+");
else if ((Mode & WriteOnly) == WriteOnly)
- d->gz = gzdopen(iFd, "w");
+ compress_struct = compress_open(iFd, "w");
else
- d->gz = gzdopen(iFd, "r");
- if (d->gz == NULL)
+ compress_struct = compress_open(iFd, "r");
+ if (compress_struct == NULL)
return false;
- Flags |= Compressed;
- return true;
- }
+
+ if (false)
+ /* dummy so that the rest can be 'else if's */;
+#ifdef HAVE_ZLIB
+ else if (compressor.Name == "gzip")
+ d->gz = (gzFile) compress_struct;
#endif
#ifdef HAVE_BZ2
- if (compressor.Name == "bzip2")
- {
- if (d->bz2 != NULL)
+ else if (compressor.Name == "bzip2")
+ d->bz2 = (BZFILE*) compress_struct;
+#endif
+#ifdef HAVE_LZMA
+ else if (compressor.Name == "xz" || compressor.Name == "lzma")
{
- BZ2_bzclose(d->bz2);
- d->bz2 = NULL;
+ uint32_t const xzlevel = 6;
+ uint64_t const memlimit = UINT64_MAX;
+ if (d->lzma == NULL)
+ d->lzma = new FileFdPrivate::LZMAFILE;
+ d->lzma->file = (FILE*) compress_struct;
+ d->lzma->stream = LZMA_STREAM_INIT;
+
+ if ((Mode & ReadWrite) == ReadWrite)
+ return FileFdError("ReadWrite mode is not supported for file %s", FileName.c_str());
+
+ if ((Mode & WriteOnly) == WriteOnly)
+ {
+ if (compressor.Name == "xz")
+ {
+ if (lzma_easy_encoder(&d->lzma->stream, xzlevel, LZMA_CHECK_CRC32) != LZMA_OK)
+ return false;
+ }
+ else
+ {
+ lzma_options_lzma options;
+ lzma_lzma_preset(&options, xzlevel);
+ if (lzma_alone_encoder(&d->lzma->stream, &options) != LZMA_OK)
+ return false;
+ }
+ d->lzma->compressing = true;
+ }
+ else
+ {
+ if (compressor.Name == "xz")
+ {
+ if (lzma_auto_decoder(&d->lzma->stream, memlimit, 0) != LZMA_OK)
+ return false;
+ }
+ else
+ {
+ if (lzma_alone_decoder(&d->lzma->stream, memlimit) != LZMA_OK)
+ return false;
+ }
+ d->lzma->compressing = false;
+ }
}
- if ((Mode & ReadWrite) == ReadWrite)
- d->bz2 = BZ2_bzdopen(iFd, "r+");
- else if ((Mode & WriteOnly) == WriteOnly)
- d->bz2 = BZ2_bzdopen(iFd, "w");
- else
- d->bz2 = BZ2_bzdopen(iFd, "r");
- if (d->bz2 == NULL)
- return false;
+#endif
Flags |= Compressed;
return true;
}
@@ -1198,7 +1326,7 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C
}
else
{
- if (FileName.empty() == true)
+ if (d->compressed_fd != -1)
dup2(d->compressed_fd,STDIN_FILENO);
dup2(Pipe[1],STDOUT_FILENO);
}
@@ -1267,24 +1395,55 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual)
*((char *)To) = '\0';
do
{
+ if (false)
+ /* dummy so that the rest can be 'else if's */;
#ifdef HAVE_ZLIB
- if (d != NULL && d->gz != NULL)
+ else if (d != NULL && d->gz != NULL)
Res = gzread(d->gz,To,Size);
- else
#endif
#ifdef HAVE_BZ2
- if (d != NULL && d->bz2 != NULL)
+ else if (d != NULL && d->bz2 != NULL)
Res = BZ2_bzread(d->bz2,To,Size);
- else
#endif
+#ifdef HAVE_LZMA
+ else if (d != NULL && d->lzma != NULL)
+ {
+ if (d->lzma->eof == true)
+ break;
+
+ d->lzma->stream.next_out = (uint8_t *) To;
+ d->lzma->stream.avail_out = Size;
+ if (d->lzma->stream.avail_in == 0)
+ {
+ d->lzma->stream.next_in = d->lzma->buffer;
+ d->lzma->stream.avail_in = fread(d->lzma->buffer, 1, sizeof(d->lzma->buffer)/sizeof(d->lzma->buffer[0]), d->lzma->file);
+ }
+ d->lzma->err = lzma_code(&d->lzma->stream, LZMA_RUN);
+ if (d->lzma->err == LZMA_STREAM_END)
+ {
+ d->lzma->eof = true;
+ Res = Size - d->lzma->stream.avail_out;
+ }
+ else if (d->lzma->err != LZMA_OK)
+ {
+ Res = -1;
+ errno = 0;
+ }
+ else
+ Res = Size - d->lzma->stream.avail_out;
+ }
+#endif
+ else
Res = read(iFd,To,Size);
if (Res < 0)
{
if (errno == EINTR)
continue;
+ if (false)
+ /* dummy so that the rest can be 'else if's */;
#ifdef HAVE_ZLIB
- if (d != NULL && d->gz != NULL)
+ else if (d != NULL && d->gz != NULL)
{
int err;
char const * const errmsg = gzerror(d->gz, &err);
@@ -1293,7 +1452,7 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual)
}
#endif
#ifdef HAVE_BZ2
- if (d != NULL && d->bz2 != NULL)
+ else if (d != NULL && d->bz2 != NULL)
{
int err;
char const * const errmsg = BZ2_bzerror(d->bz2, &err);
@@ -1301,6 +1460,10 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual)
return FileFdError("BZ2_bzread: %s (%d: %s)", _("Read error"), err, errmsg);
}
#endif
+#ifdef HAVE_LZMA
+ else if (d != NULL && d->lzma != NULL)
+ return FileFdError("lzma_read: %s (%d)", _("Read error"), d->lzma->err);
+#endif
return FileFdErrno("read",_("Read error"));
}
@@ -1364,23 +1527,45 @@ bool FileFd::Write(const void *From,unsigned long long Size)
errno = 0;
do
{
+ if (false)
+ /* dummy so that the rest can be 'else if's */;
#ifdef HAVE_ZLIB
- if (d != NULL && d->gz != NULL)
- Res = gzwrite(d->gz,From,Size);
- else
+ else if (d != NULL && d->gz != NULL)
+ Res = gzwrite(d->gz,From,Size);
#endif
#ifdef HAVE_BZ2
- if (d != NULL && d->bz2 != NULL)
- Res = BZ2_bzwrite(d->bz2,(void*)From,Size);
- else
+ else if (d != NULL && d->bz2 != NULL)
+ Res = BZ2_bzwrite(d->bz2,(void*)From,Size);
+#endif
+#ifdef HAVE_LZMA
+ else if (d != NULL && d->lzma != NULL)
+ {
+ d->lzma->stream.next_in = (uint8_t *)From;
+ d->lzma->stream.avail_in = Size;
+ d->lzma->stream.next_out = d->lzma->buffer;
+ d->lzma->stream.avail_out = sizeof(d->lzma->buffer)/sizeof(d->lzma->buffer[0]);
+ d->lzma->err = lzma_code(&d->lzma->stream, LZMA_RUN);
+ if (d->lzma->err != LZMA_OK)
+ return false;
+ size_t const n = sizeof(d->lzma->buffer)/sizeof(d->lzma->buffer[0]) - d->lzma->stream.avail_out;
+ size_t const m = (n == 0) ? 0 : fwrite(d->lzma->buffer, 1, n, d->lzma->file);
+ if (m != n)
+ Res = -1;
+ else
+ Res = Size - d->lzma->stream.avail_in;
+ }
#endif
- Res = write(iFd,From,Size);
+ else
+ Res = write(iFd,From,Size);
+
if (Res < 0 && errno == EINTR)
continue;
if (Res < 0)
{
+ if (false)
+ /* dummy so that the rest can be 'else if's */;
#ifdef HAVE_ZLIB
- if (d != NULL && d->gz != NULL)
+ else if (d != NULL && d->gz != NULL)
{
int err;
char const * const errmsg = gzerror(d->gz, &err);
@@ -1389,7 +1574,7 @@ bool FileFd::Write(const void *From,unsigned long long Size)
}
#endif
#ifdef HAVE_BZ2
- if (d != NULL && d->bz2 != NULL)
+ else if (d != NULL && d->bz2 != NULL)
{
int err;
char const * const errmsg = BZ2_bzerror(d->bz2, &err);
@@ -1397,10 +1582,14 @@ bool FileFd::Write(const void *From,unsigned long long Size)
return FileFdError("BZ2_bzwrite: %s (%d: %s)", _("Write error"), err, errmsg);
}
#endif
+#ifdef HAVE_LZMA
+ else if (d != NULL && d->lzma != NULL)
+ return FileFdErrno("lzma_fwrite", _("Write error"));
+#endif
return FileFdErrno("write",_("Write error"));
}
- From = (char *)From + Res;
+ From = (char const *)From + Res;
Size -= Res;
if (d != NULL)
d->seekpos += Res;
@@ -1424,7 +1613,7 @@ bool FileFd::Write(int Fd, const void *From, unsigned long long Size)
if (Res < 0)
return _error->Errno("write",_("Write error"));
- From = (char *)From + Res;
+ From = (char const *)From + Res;
Size -= Res;
}
while (Res > 0 && Size > 0);
@@ -1440,11 +1629,7 @@ bool FileFd::Write(int Fd, const void *From, unsigned long long Size)
/* */
bool FileFd::Seek(unsigned long long To)
{
- if (d != NULL && (d->pipe == true
-#ifdef HAVE_BZ2
- || d->bz2 != NULL
-#endif
- ))
+ if (d != NULL && (d->pipe == true || d->InternalStream() == true))
{
// Our poor man seeking in pipes is costly, so try to avoid it
unsigned long long seekpos = Tell();
@@ -1455,13 +1640,7 @@ bool FileFd::Seek(unsigned long long To)
if ((d->openmode & ReadOnly) != ReadOnly)
return FileFdError("Reopen is only implemented for read-only files!");
-#ifdef HAVE_BZ2
- if (d->bz2 != NULL)
- {
- BZ2_bzclose(d->bz2);
- d->bz2 = NULL;
- }
-#endif
+ d->InternalClose(FileName);
if (iFd != -1)
close(iFd);
iFd = -1;
@@ -1507,11 +1686,7 @@ bool FileFd::Seek(unsigned long long To)
/* */
bool FileFd::Skip(unsigned long long Over)
{
- if (d != NULL && (d->pipe == true
-#ifdef HAVE_BZ2
- || d->bz2 != NULL
-#endif
- ))
+ if (d != NULL && (d->pipe == true || d->InternalStream() == true))
{
d->seekpos += Over;
char buffer[1024];
@@ -1548,8 +1723,12 @@ bool FileFd::Truncate(unsigned long long To)
// truncating /dev/null is always successful - as we get an error otherwise
if (To == 0 && FileName == "/dev/null")
return true;
-#if defined HAVE_ZLIB || defined HAVE_BZ2
- if (d != NULL && (d->gz != NULL || d->bz2 != NULL))
+#if defined HAVE_ZLIB || defined HAVE_BZ2 || defined HAVE_LZMA
+ if (d != NULL && (d->InternalStream() == true
+#ifdef HAVE_ZLIB
+ || d->gz != NULL
+#endif
+ ))
return FileFdError("Truncating compressed files is not implemented (%s)", FileName.c_str());
#endif
if (ftruncate(iFd,To) != 0)
@@ -1567,11 +1746,7 @@ unsigned long long FileFd::Tell()
// seeking around, but not all users of FileFd use always Seek() and co
// so d->seekpos isn't always true and we can just use it as a hint if
// we have nothing else, but not always as an authority…
- if (d != NULL && (d->pipe == true
-#ifdef HAVE_BZ2
- || d->bz2 != NULL
-#endif
- ))
+ if (d != NULL && (d->pipe == true || d->InternalStream() == true))
return d->seekpos;
off_t Res;
@@ -1646,11 +1821,7 @@ unsigned long long FileFd::Size()
// for compressor pipes st_size is undefined and at 'best' zero,
// so we 'read' the content and 'seek' back - see there
- if (d != NULL && (d->pipe == true
-#ifdef HAVE_BZ2
- || (d->bz2 && size > 0)
-#endif
- ))
+ if (d != NULL && (d->pipe == true || (d->InternalStream() == true && size > 0)))
{
unsigned long long const oldSeek = Tell();
char ignore[1000];
@@ -1793,7 +1964,13 @@ bool FileFd::FileFdError(const char *Description,...) {
}
/*}}}*/
-gzFile FileFd::gzFd() { return (gzFile) d->gz; }
+APT_DEPRECATED gzFile FileFd::gzFd() {
+#ifdef HAVE_ZLIB
+ return d->gz;
+#else
+ return NULL;
+#endif
+}
// Glob - wrapper around "glob()" /*{{{*/
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index f0569b6fd..278a25742 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -27,6 +27,7 @@
#include <string>
#include <vector>
#include <set>
+#include <time.h>
#include <zlib.h>
@@ -94,7 +95,7 @@ class FileFd
And as the auto-conversation converts a 'unsigned long *' to a 'bool'
instead of 'unsigned long long *' we need to provide this explicitely -
otherwise applications magically start to fail… */
- __deprecated bool Read(void *To,unsigned long long Size,unsigned long *Actual)
+ bool Read(void *To,unsigned long long Size,unsigned long *Actual) APT_DEPRECATED
{
unsigned long long R;
bool const T = Read(To, Size, &R);
@@ -118,7 +119,7 @@ class FileFd
// Simple manipulators
inline int Fd() {return iFd;};
inline void Fd(int fd) { OpenDescriptor(fd, ReadWrite);};
- __deprecated gzFile gzFd();
+ gzFile gzFd() APT_DEPRECATED APT_PURE;
inline bool IsOpen() {return iFd >= 0;};
inline bool Failed() {return (Flags & Fail) == Fail;};
@@ -152,8 +153,8 @@ class FileFd
bool OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor);
// private helpers to set Fail flag and call _error->Error
- bool FileFdErrno(const char* Function, const char* Description,...) __like_printf(3) __cold;
- bool FileFdError(const char* Description,...) __like_printf(2) __cold;
+ bool FileFdErrno(const char* Function, const char* Description,...) APT_PRINTF(3) APT_COLD;
+ bool FileFdError(const char* Description,...) APT_PRINTF(2) APT_COLD;
};
bool RunScripts(const char *Cnf);
@@ -161,7 +162,7 @@ bool CopyFile(FileFd &From,FileFd &To);
int GetLock(std::string File,bool Errors = true);
bool FileExists(std::string File);
bool RealFileExists(std::string File);
-bool DirectoryExists(std::string const &Path) __attrib_const;
+bool DirectoryExists(std::string const &Path) APT_CONST;
bool CreateDirectory(std::string const &Parent, std::string const &Path);
time_t GetModificationTime(std::string const &Path);
bool Rename(std::string From, std::string To);
diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc
index 9de227062..f24dd9640 100644
--- a/apt-pkg/contrib/gpgv.cc
+++ b/apt-pkg/contrib/gpgv.cc
@@ -2,21 +2,23 @@
// Include Files /*{{{*/
#include<config.h>
+#include<apt-pkg/configuration.h>
+#include<apt-pkg/error.h>
+#include<apt-pkg/strutl.h>
+#include<apt-pkg/fileutl.h>
+#include<apt-pkg/gpgv.h>
+
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
-
-#include<apt-pkg/configuration.h>
-#include<apt-pkg/error.h>
-#include<apt-pkg/strutl.h>
-#include<apt-pkg/fileutl.h>
-#include<apt-pkg/gpgv.h>
+#include <stddef.h>
+#include <iostream>
+#include <string>
+#include <vector>
#include <apti18n.h>
/*}}}*/
diff --git a/apt-pkg/contrib/gpgv.h b/apt-pkg/contrib/gpgv.h
index 1d79a52ac..f018893fd 100644
--- a/apt-pkg/contrib/gpgv.h
+++ b/apt-pkg/contrib/gpgv.h
@@ -9,17 +9,17 @@
#ifndef CONTRIB_GPGV_H
#define CONTRIB_GPGV_H
+#include <apt-pkg/macros.h>
+
#include <string>
#include <vector>
+#ifndef APT_10_CLEANER_HEADERS
#include <apt-pkg/fileutl.h>
-
-#if __GNUC__ >= 4
- #define APT_noreturn __attribute__ ((noreturn))
-#else
- #define APT_noreturn /* no support */
#endif
+class FileFd;
+
/** \brief generates and run the command to verify a file with gpgv
*
* If File and FileSig specify the same file it is assumed that we
@@ -40,14 +40,12 @@
* @param FileSig is the signature (detached or clear-signed)
*/
void ExecGPGV(std::string const &File, std::string const &FileSig,
- int const &statusfd, int fd[2]) APT_noreturn;
-inline void ExecGPGV(std::string const &File, std::string const &FileSig,
+ int const &statusfd, int fd[2]) APT_NORETURN;
+inline APT_NORETURN void ExecGPGV(std::string const &File, std::string const &FileSig,
int const &statusfd = -1) {
int fd[2];
ExecGPGV(File, FileSig, statusfd, fd);
-};
-
-#undef APT_noreturn
+}
/** \brief Split an inline signature into message and signature
*
diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc
index 890573d9c..1fce0d75f 100644
--- a/apt-pkg/contrib/hashes.cc
+++ b/apt-pkg/contrib/hashes.cc
@@ -16,8 +16,12 @@
#include <apt-pkg/hashes.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/configuration.h>
-#include <apt-pkg/macros.h>
+#include <apt-pkg/md5.h>
+#include <apt-pkg/sha1.h>
+#include <apt-pkg/sha2.h>
+#include <stddef.h>
+#include <algorithm>
#include <unistd.h>
#include <string>
#include <iostream>
@@ -112,7 +116,7 @@ const char** HashString::SupportedHashes()
return _SupportedHashes;
}
-bool HashString::empty() const
+APT_PURE bool HashString::empty() const
{
return (Type.empty() || Hash.empty());
}
diff --git a/apt-pkg/contrib/hashes.h b/apt-pkg/contrib/hashes.h
index 0a8bcd259..5cd1af03b 100644
--- a/apt-pkg/contrib/hashes.h
+++ b/apt-pkg/contrib/hashes.h
@@ -17,17 +17,22 @@
#include <apt-pkg/md5.h>
#include <apt-pkg/sha1.h>
#include <apt-pkg/sha2.h>
-#include <apt-pkg/fileutl.h>
-#include <algorithm>
-#include <vector>
#include <cstring>
-
+#include <string>
#ifndef APT_8_CLEANER_HEADERS
using std::min;
using std::vector;
#endif
+#ifndef APT_10_CLEANER_HEADERS
+#include <apt-pkg/fileutl.h>
+#include <algorithm>
+#include <vector>
+#endif
+
+
+class FileFd;
// helper class that contains hash function name
// and hash
@@ -61,7 +66,7 @@ class HashString
bool empty() const;
// return the list of hashes we support
- static const char** SupportedHashes();
+ static APT_CONST const char** SupportedHashes();
};
class Hashes
@@ -77,7 +82,7 @@ class Hashes
{
return MD5.Add(Data,Size) && SHA1.Add(Data,Size) && SHA256.Add(Data,Size) && SHA512.Add(Data,Size);
};
- inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
+ inline bool Add(const char *Data) {return Add((unsigned char const *)Data,strlen(Data));};
inline bool AddFD(int const Fd,unsigned long long Size = 0)
{ return AddFD(Fd, Size, true, true, true, true); };
bool AddFD(int const Fd, unsigned long long Size, bool const addMD5,
diff --git a/apt-pkg/contrib/hashsum.cc b/apt-pkg/contrib/hashsum.cc
index d02177724..25ccc187d 100644
--- a/apt-pkg/contrib/hashsum.cc
+++ b/apt-pkg/contrib/hashsum.cc
@@ -1,6 +1,9 @@
// Cryptographic API Base
#include <config.h>
+#include <apt-pkg/fileutl.h>
+
+#include <algorithm>
#include <unistd.h>
#include "hashsum_template.h"
diff --git a/apt-pkg/contrib/hashsum_template.h b/apt-pkg/contrib/hashsum_template.h
index 9bf160b2b..869dc5cb7 100644
--- a/apt-pkg/contrib/hashsum_template.h
+++ b/apt-pkg/contrib/hashsum_template.h
@@ -10,36 +10,40 @@
#ifndef APTPKG_HASHSUM_TEMPLATE_H
#define APTPKG_HASHSUM_TEMPLATE_H
-#include <apt-pkg/fileutl.h>
#include <string>
#include <cstring>
-#include <algorithm>
-#include <stdint.h>
#include <apt-pkg/strutl.h>
+#ifndef APT_10_CLEANER_HEADERS
+#include <apt-pkg/fileutl.h>
+#include <algorithm>
+#include <stdint.h>
+#endif
#ifndef APT_8_CLEANER_HEADERS
using std::string;
using std::min;
#endif
+class FileFd;
+
template<int N>
class HashSumValue
{
unsigned char Sum[N/8];
-
+
public:
// Accessors
bool operator ==(const HashSumValue &rhs) const
{
return memcmp(Sum,rhs.Sum,sizeof(Sum)) == 0;
- };
+ }
bool operator !=(const HashSumValue &rhs) const
{
return memcmp(Sum,rhs.Sum,sizeof(Sum)) != 0;
- };
+ }
std::string Value() const
{
@@ -49,7 +53,7 @@ class HashSumValue
};
char Result[((N/8)*2)+1];
Result[(N/8)*2] = 0;
-
+
// Convert each char into two letters
int J = 0;
int I = 0;
@@ -59,31 +63,31 @@ class HashSumValue
Result[I + 1] = Conv[Sum[J] & 0xF];
}
return std::string(Result);
- };
-
+ }
+
inline void Value(unsigned char S[N/8])
{
- for (int I = 0; I != sizeof(Sum); I++)
+ for (int I = 0; I != sizeof(Sum); ++I)
S[I] = Sum[I];
- };
+ }
- inline operator std::string() const
+ inline operator std::string() const
{
return Value();
- };
+ }
- bool Set(std::string Str)
+ bool Set(std::string Str)
{
return Hex2Num(Str,Sum,sizeof(Sum));
- };
+ }
- inline void Set(unsigned char S[N/8])
+ inline void Set(unsigned char S[N/8])
{
- for (int I = 0; I != sizeof(Sum); I++)
+ for (int I = 0; I != sizeof(Sum); ++I)
Sum[I] = S[I];
- };
+ }
- HashSumValue(std::string Str)
+ HashSumValue(std::string Str)
{
memset(Sum,0,sizeof(Sum));
Set(Str);
@@ -99,17 +103,17 @@ class SummationImplementation
public:
virtual bool Add(const unsigned char *inbuf, unsigned long long inlen) = 0;
inline bool Add(const char *inbuf, unsigned long long const inlen)
- { return Add((unsigned char *)inbuf, inlen); };
+ { return Add((const unsigned char *)inbuf, inlen); }
inline bool Add(const unsigned char *Data)
- { return Add(Data, strlen((const char *)Data)); };
+ { return Add(Data, strlen((const char *)Data)); }
inline bool Add(const char *Data)
- { return Add((const unsigned char *)Data, strlen((const char *)Data)); };
+ { return Add((const unsigned char *)Data, strlen(Data)); }
inline bool Add(const unsigned char *Beg, const unsigned char *End)
- { return Add(Beg, End - Beg); };
+ { return Add(Beg, End - Beg); }
inline bool Add(const char *Beg, const char *End)
- { return Add((const unsigned char *)Beg, End - Beg); };
+ { return Add((const unsigned char *)Beg, End - Beg); }
bool AddFD(int Fd, unsigned long long Size = 0);
bool AddFD(FileFd &Fd, unsigned long long Size = 0);
diff --git a/apt-pkg/contrib/macros.h b/apt-pkg/contrib/macros.h
index e53d01b8f..d97053553 100644
--- a/apt-pkg/contrib/macros.h
+++ b/apt-pkg/contrib/macros.h
@@ -54,37 +54,87 @@
#define CLRFLAG(v,f) ((v) &=~FLAG(f))
#define CHKFLAG(v,f) ((v) & FLAG(f) ? true : false)
-// some nice optional GNUC features
-#if __GNUC__ >= 3
- #define __must_check __attribute__ ((warn_unused_result))
- #define __deprecated __attribute__ ((deprecated))
- #define __attrib_const __attribute__ ((__const__))
- /* likely() and unlikely() can be used to mark boolean expressions
- as (not) likely true which will help the compiler to optimise */
+#ifdef __GNUC__
+#define APT_GCC_VERSION (__GNUC__ << 8 | __GNUC_MINOR__)
+#else
+#define APT_GCC_VERSION 0
+#endif
+
+/* likely() and unlikely() can be used to mark boolean expressions
+ as (not) likely true which will help the compiler to optimise */
+#if APT_GCC_VERSION >= 0x0300
#define likely(x) __builtin_expect (!!(x), 1)
#define unlikely(x) __builtin_expect (!!(x), 0)
#else
- #define __must_check /* no warn_unused_result */
- #define __deprecated /* no deprecated */
- #define __attrib_const /* no const attribute */
#define likely(x) (x)
#define unlikely(x) (x)
#endif
+#if APT_GCC_VERSION >= 0x0300
+ #define APT_DEPRECATED __attribute__ ((deprecated))
+ #define APT_CONST __attribute__((const))
+ #define APT_PURE __attribute__((pure))
+ #define APT_NORETURN __attribute__((noreturn))
+ #define APT_PRINTF(n) __attribute__((format(printf, n, n + 1)))
+#else
+ #define APT_DEPRECATED
+ #define APT_CONST
+ #define APT_PURE
+ #define APT_NORETURN
+ #define APT_PRINTF(n)
+#endif
+
+#if APT_GCC_VERSION > 0x0302
+ #define APT_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
+ #define APT_MUSTCHECK __attribute__((warn_unused_result))
+#else
+ #define APT_NONNULL(...)
+ #define APT_REQRET
+#endif
+
+#if APT_GCC_VERSION >= 0x0400
+ #define APT_SENTINEL __attribute__((sentinel))
+#else
+ #define APT_SENTINEL
+#endif
+
// cold functions are unlikely() to be called
-#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4
- #define __cold __attribute__ ((__cold__))
- #define __hot __attribute__ ((__hot__))
+#if APT_GCC_VERSION >= 0x0403
+ #define APT_COLD __attribute__ ((__cold__))
+ #define APT_HOT __attribute__ ((__hot__))
#else
- #define __cold /* no cold marker */
- #define __hot /* no hot marker */
+ #define APT_COLD
+ #define APT_HOT
#endif
-#ifdef __GNUG__
-// Methods have a hidden this parameter that is visible to this attribute
+#ifndef APT_10_CLEANER_HEADERS
+#if APT_GCC_VERSION >= 0x0300
+ #define __must_check __attribute__ ((warn_unused_result))
+ #define __deprecated __attribute__ ((deprecated))
+ #define __attrib_const __attribute__ ((__const__))
#define __like_printf(n) __attribute__((format(printf, n, n + 1)))
#else
+ #define __must_check /* no warn_unused_result */
+ #define __deprecated /* no deprecated */
+ #define __attrib_const /* no const attribute */
#define __like_printf(n) /* no like-printf */
#endif
+#if APT_GCC_VERSION >= 0x0403
+ #define __cold __attribute__ ((__cold__))
+ #define __hot __attribute__ ((__hot__))
+#else
+ #define __cold /* no cold marker */
+ #define __hot /* no hot marker */
+#endif
+#endif
+
+// These lines are extracted by the makefiles and the buildsystem
+// Increasing MAJOR or MINOR results in the need of recompiling all
+// reverse-dependencies of libapt-pkg against the new SONAME.
+// Non-ABI-Breaks should only increase RELEASE number.
+// See also buildlib/libversion.mak
+#define APT_PKG_MAJOR 4
+#define APT_PKG_MINOR 12
+#define APT_PKG_RELEASE 0
#endif
diff --git a/apt-pkg/contrib/md5.cc b/apt-pkg/contrib/md5.cc
index 4351aeb22..b487a96f9 100644
--- a/apt-pkg/contrib/md5.cc
+++ b/apt-pkg/contrib/md5.cc
@@ -38,13 +38,9 @@
#include <config.h>
#include <apt-pkg/md5.h>
-#include <apt-pkg/strutl.h>
-#include <apt-pkg/macros.h>
+#include <stdint.h>
#include <string.h>
-#include <unistd.h>
-#include <netinet/in.h> // For htonl
-#include <inttypes.h>
/*}}}*/
// byteSwap - Swap bytes in a buffer /*{{{*/
diff --git a/apt-pkg/contrib/md5.h b/apt-pkg/contrib/md5.h
index 195455645..f4992c223 100644
--- a/apt-pkg/contrib/md5.h
+++ b/apt-pkg/contrib/md5.h
@@ -23,14 +23,15 @@
#ifndef APTPKG_MD5_H
#define APTPKG_MD5_H
-
-#include <string>
-#include <cstring>
-#include <algorithm>
#include <stdint.h>
#include "hashsum_template.h"
+#ifndef APT_10_CLEANER_HEADERS
+#include <string>
+#include <cstring>
+#include <algorithm>
+#endif
#ifndef APT_8_CLEANER_HEADERS
using std::string;
using std::min;
diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc
index 51e8eb30f..b2a53a6cb 100644
--- a/apt-pkg/contrib/mmap.cc
+++ b/apt-pkg/contrib/mmap.cc
@@ -22,11 +22,11 @@
#include <apt-pkg/mmap.h>
#include <apt-pkg/error.h>
#include <apt-pkg/fileutl.h>
+#include <apt-pkg/macros.h>
+#include <string>
#include <sys/mman.h>
-#include <sys/stat.h>
#include <unistd.h>
-#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include <cstring>
@@ -198,7 +198,7 @@ bool MMap::Sync(unsigned long Start,unsigned long Stop)
{
#ifdef _POSIX_SYNCHRONIZED_IO
unsigned long long const PSize = sysconf(_SC_PAGESIZE);
- if (msync((char *)Base+(unsigned long long)(Start/PSize)*PSize,Stop - Start,MS_SYNC) < 0)
+ if (msync((char *)Base+(Start/PSize)*PSize, Stop - Start, MS_SYNC) < 0)
return _error->Errno("msync", _("Unable to synchronize mmap"));
#endif
}
diff --git a/apt-pkg/contrib/netrc.cc b/apt-pkg/contrib/netrc.cc
index de95aa4ab..feaed67c8 100644
--- a/apt-pkg/contrib/netrc.cc
+++ b/apt-pkg/contrib/netrc.cc
@@ -15,14 +15,13 @@
#include <apt-pkg/configuration.h>
#include <apt-pkg/strutl.h>
-#include <apt-pkg/error.h>
-#include <apt-pkg/fileutl.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <stddef.h>
#include <pwd.h>
#include "netrc.h"
@@ -198,7 +197,7 @@ void maybe_add_auth (URI &Uri, string NetRCFile)
// if host did not work, try Host+Path next, this will trigger
// a lookup uri.startswith(host) in the netrc file parser (because
// of the "/"
- char *hostpath = strdup(string(Uri.Host+Uri.Path).c_str());
+ char *hostpath = strdup((Uri.Host + Uri.Path).c_str());
if (hostpath && parsenetrc_string(hostpath, login, password, netrcfile) == 0)
{
if (_config->FindB("Debug::Acquire::netrc", false) == true)
diff --git a/apt-pkg/contrib/netrc.h b/apt-pkg/contrib/netrc.h
index 6feb5b726..dbeb45386 100644
--- a/apt-pkg/contrib/netrc.h
+++ b/apt-pkg/contrib/netrc.h
@@ -16,6 +16,8 @@
#include <string>
+#include <apt-pkg/macros.h>
+
#ifndef APT_8_CLEANER_HEADERS
#include <apt-pkg/strutl.h>
#endif
@@ -25,9 +27,9 @@
class URI;
-// kill this export on the next ABI break - strongly doubt its in use anyway
+// FIXME: kill this export on the next ABI break - strongly doubt its in use anyway
// outside of the apt itself, its really a internal interface
-__deprecated int parsenetrc (char *host, char *login, char *password, char *filename);
+APT_DEPRECATED int parsenetrc (char *host, char *login, char *password, char *filename);
void maybe_add_auth (URI &Uri, std::string NetRCFile);
#endif
diff --git a/apt-pkg/contrib/progress.cc b/apt-pkg/contrib/progress.cc
index 916e1d730..4ff4f181d 100644
--- a/apt-pkg/contrib/progress.cc
+++ b/apt-pkg/contrib/progress.cc
@@ -14,6 +14,8 @@
#include <apt-pkg/error.h>
#include <apt-pkg/configuration.h>
+#include <sys/time.h>
+#include <string>
#include <iostream>
#include <stdio.h>
#include <cstring>
@@ -125,14 +127,14 @@ bool OpProgress::CheckChange(float Interval)
// OpTextProgress::OpTextProgress - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
-OpTextProgress::OpTextProgress(Configuration &Config) :
- NoUpdate(false), NoDisplay(false), LastLen(0)
+OpTextProgress::OpTextProgress(Configuration &Config) :
+ NoUpdate(false), NoDisplay(false), LastLen(0)
{
if (Config.FindI("quiet",0) >= 1 || Config.FindB("quiet::NoUpdate", false) == true)
NoUpdate = true;
if (Config.FindI("quiet",0) >= 2)
NoDisplay = true;
-};
+}
/*}}}*/
// OpTextProgress::Done - Clean up the display /*{{{*/
// ---------------------------------------------------------------------
@@ -150,12 +152,12 @@ void OpTextProgress::Done()
cout << endl;
OldOp = string();
}
-
+
if (NoUpdate == true && NoDisplay == false && OldOp.empty() == false)
{
OldOp = string();
- cout << endl;
- }
+ cout << endl;
+ }
}
/*}}}*/
// OpTextProgress::Update - Simple text spinner /*{{{*/
diff --git a/apt-pkg/contrib/sha1.cc b/apt-pkg/contrib/sha1.cc
index b5a6a2440..bf6bc6cb6 100644
--- a/apt-pkg/contrib/sha1.cc
+++ b/apt-pkg/contrib/sha1.cc
@@ -32,12 +32,9 @@
#include <config.h>
#include <apt-pkg/sha1.h>
-#include <apt-pkg/strutl.h>
-#include <apt-pkg/macros.h>
+#include <stdint.h>
#include <string.h>
-#include <unistd.h>
-#include <inttypes.h>
/*}}}*/
// SHA1Transform - Alters an existing SHA-1 hash /*{{{*/
diff --git a/apt-pkg/contrib/sha1.h b/apt-pkg/contrib/sha1.h
index a8d55eb13..5770c315a 100644
--- a/apt-pkg/contrib/sha1.h
+++ b/apt-pkg/contrib/sha1.h
@@ -14,12 +14,13 @@
#ifndef APTPKG_SHA1_H
#define APTPKG_SHA1_H
+#include "hashsum_template.h"
+
+#ifndef APT_10_CLEANER_HEADERS
#include <string>
#include <cstring>
#include <algorithm>
-
-#include "hashsum_template.h"
-
+#endif
#ifndef APT_8_CLEANER_HEADERS
using std::string;
using std::min;
diff --git a/apt-pkg/contrib/sha2.h b/apt-pkg/contrib/sha2.h
index 8e0c99a1b..a25ad4d32 100644
--- a/apt-pkg/contrib/sha2.h
+++ b/apt-pkg/contrib/sha2.h
@@ -14,14 +14,18 @@
#ifndef APTPKG_SHA2_H
#define APTPKG_SHA2_H
-#include <string>
#include <cstring>
-#include <algorithm>
-#include <stdint.h>
#include "sha2_internal.h"
#include "hashsum_template.h"
+#ifndef APT_10_CLEANER_HEADERS
+#include <string>
+#include <algorithm>
+#include <stdint.h>
+#endif
+
+
typedef HashSumValue<512> SHA512SumValue;
typedef HashSumValue<256> SHA256SumValue;
diff --git a/apt-pkg/contrib/sha2_internal.cc b/apt-pkg/contrib/sha2_internal.cc
index bb2560252..131ff5beb 100644
--- a/apt-pkg/contrib/sha2_internal.cc
+++ b/apt-pkg/contrib/sha2_internal.cc
@@ -33,6 +33,7 @@
*/
#include <config.h>
+#include <endian.h>
#include <string.h> /* memcpy()/memset() or bcopy()/bzero() */
#include <assert.h> /* assert() */
#include "sha2_internal.h"
diff --git a/apt-pkg/contrib/sha2_internal.h b/apt-pkg/contrib/sha2_internal.h
index d9d429c92..1b82d965d 100644
--- a/apt-pkg/contrib/sha2_internal.h
+++ b/apt-pkg/contrib/sha2_internal.h
@@ -44,6 +44,7 @@
#ifdef SHA2_USE_INTTYPES_H
+#include <stddef.h>
#include <inttypes.h>
#endif /* SHA2_USE_INTTYPES_H */
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index d4f53ea3a..2100ee47b 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -21,6 +21,11 @@
#include <apt-pkg/fileutl.h>
#include <apt-pkg/error.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <time.h>
+#include <string>
+#include <vector>
#include <ctype.h>
#include <string.h>
#include <sstream>
@@ -33,9 +38,9 @@
#include <iconv.h>
#include <apti18n.h>
-
-using namespace std;
/*}}}*/
+using namespace std;
+
// Strip - Remove white space from the front and back of a string /*{{{*/
// ---------------------------------------------------------------------
namespace APT {
@@ -153,7 +158,7 @@ char *_strrstrip(char *String)
End++;
*End = 0;
return String;
-};
+}
/*}}}*/
// strtabexpand - Converts tabs into 8 spaces /*{{{*/
// ---------------------------------------------------------------------
@@ -1130,9 +1135,11 @@ bool TokSplitString(char Tok,char *Input,char **List,
also, but the advantage is that we have an iteratable vector */
vector<string> VectorizeString(string const &haystack, char const &split)
{
+ vector<string> exploded;
+ if (haystack.empty() == true)
+ return exploded;
string::const_iterator start = haystack.begin();
string::const_iterator end = start;
- vector<string> exploded;
do {
for (; end != haystack.end() && *end != split; ++end);
exploded.push_back(string(start, end));
@@ -1182,7 +1189,7 @@ unsigned long RegexChoice(RxChoiceList *Rxs,const char **ListBegin,
R->Hit = false;
unsigned long Hits = 0;
- for (; ListBegin != ListEnd; ListBegin++)
+ for (; ListBegin < ListEnd; ++ListBegin)
{
// Check if the name is a regex
const char *I;
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index 8d746f10e..185cdc3fc 100644
--- a/apt-pkg/contrib/strutl.h
+++ b/apt-pkg/contrib/strutl.h
@@ -18,15 +18,18 @@
#include <limits>
-#include <stdlib.h>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <time.h>
+#include <stddef.h>
#include "macros.h"
+#ifndef APT_10_CLEANER_HEADERS
+#include <stdlib.h>
+#endif
#ifndef APT_8_CLEANER_HEADERS
using std::string;
using std::vector;
@@ -37,8 +40,8 @@ namespace APT {
namespace String {
std::string Strip(const std::string &s);
bool Endswith(const std::string &s, const std::string &ending);
- };
-};
+ }
+}
bool UTF8ToCodeset(const char *codeset, const std::string &orig, std::string *dest);
@@ -60,9 +63,9 @@ std::string Base64Encode(const std::string &Str);
std::string OutputInDepth(const unsigned long Depth, const char* Separator=" ");
std::string URItoFileName(const std::string &URI);
std::string TimeRFC1123(time_t Date);
-bool RFC1123StrToTime(const char* const str,time_t &time) __must_check;
-bool FTPMDTMStrToTime(const char* const str,time_t &time) __must_check;
-__deprecated bool StrToTime(const std::string &Val,time_t &Result);
+bool RFC1123StrToTime(const char* const str,time_t &time) APT_MUSTCHECK;
+bool FTPMDTMStrToTime(const char* const str,time_t &time) APT_MUSTCHECK;
+APT_DEPRECATED bool StrToTime(const std::string &Val,time_t &Result);
std::string LookupTag(const std::string &Message,const char *Tag,const char *Default = 0);
int StringToBool(const std::string &Text,int Default = -1);
bool ReadMessages(int Fd, std::vector<std::string> &List);
@@ -76,7 +79,7 @@ bool TokSplitString(char Tok,char *Input,char **List,
unsigned long ListMax);
// split a given string by a char
-std::vector<std::string> VectorizeString(std::string const &haystack, char const &split) __attrib_const;
+std::vector<std::string> VectorizeString(std::string const &haystack, char const &split) APT_CONST;
/* \brief Return a vector of strings from string "input" where "sep"
* is used as the delimiter string.
@@ -94,56 +97,56 @@ std::vector<std::string> VectorizeString(std::string const &haystack, char const
*/
std::vector<std::string> StringSplit(std::string const &input,
std::string const &sep,
- unsigned int maxsplit=std::numeric_limits<unsigned int>::max()) __attrib_const;
+ unsigned int maxsplit=std::numeric_limits<unsigned int>::max()) APT_CONST;
-void ioprintf(std::ostream &out,const char *format,...) __like_printf(2);
-void strprintf(std::string &out,const char *format,...) __like_printf(2);
-char *safe_snprintf(char *Buffer,char *End,const char *Format,...) __like_printf(3);
+void ioprintf(std::ostream &out,const char *format,...) APT_PRINTF(2);
+void strprintf(std::string &out,const char *format,...) APT_PRINTF(2);
+char *safe_snprintf(char *Buffer,char *End,const char *Format,...) APT_PRINTF(3);
bool CheckDomainList(const std::string &Host, const std::string &List);
-int tolower_ascii(int const c) __attrib_const __hot;
+int tolower_ascii(int const c) APT_CONST APT_HOT;
std::string StripEpoch(const std::string &VerStr);
#define APT_MKSTRCMP(name,func) \
-inline int name(const char *A,const char *B) {return func(A,A+strlen(A),B,B+strlen(B));}; \
-inline int name(const char *A,const char *AEnd,const char *B) {return func(A,AEnd,B,B+strlen(B));}; \
-inline int name(const std::string& A,const char *B) {return func(A.c_str(),A.c_str()+A.length(),B,B+strlen(B));}; \
-inline int name(const std::string& A,const std::string& B) {return func(A.c_str(),A.c_str()+A.length(),B.c_str(),B.c_str()+B.length());}; \
-inline int name(const std::string& A,const char *B,const char *BEnd) {return func(A.c_str(),A.c_str()+A.length(),B,BEnd);};
+inline APT_PURE int name(const char *A,const char *B) {return func(A,A+strlen(A),B,B+strlen(B));} \
+inline APT_PURE int name(const char *A,const char *AEnd,const char *B) {return func(A,AEnd,B,B+strlen(B));} \
+inline APT_PURE int name(const std::string& A,const char *B) {return func(A.c_str(),A.c_str()+A.length(),B,B+strlen(B));} \
+inline APT_PURE int name(const std::string& A,const std::string& B) {return func(A.c_str(),A.c_str()+A.length(),B.c_str(),B.c_str()+B.length());} \
+inline APT_PURE int name(const std::string& A,const char *B,const char *BEnd) {return func(A.c_str(),A.c_str()+A.length(),B,BEnd);}
#define APT_MKSTRCMP2(name,func) \
-inline int name(const char *A,const char *AEnd,const char *B) {return func(A,AEnd,B,B+strlen(B));}; \
-inline int name(const std::string& A,const char *B) {return func(A.begin(),A.end(),B,B+strlen(B));}; \
-inline int name(const std::string& A,const std::string& B) {return func(A.begin(),A.end(),B.begin(),B.end());}; \
-inline int name(const std::string& A,const char *B,const char *BEnd) {return func(A.begin(),A.end(),B,BEnd);};
+inline APT_PURE int name(const char *A,const char *AEnd,const char *B) {return func(A,AEnd,B,B+strlen(B));} \
+inline APT_PURE int name(const std::string& A,const char *B) {return func(A.begin(),A.end(),B,B+strlen(B));} \
+inline APT_PURE int name(const std::string& A,const std::string& B) {return func(A.begin(),A.end(),B.begin(),B.end());} \
+inline APT_PURE int name(const std::string& A,const char *B,const char *BEnd) {return func(A.begin(),A.end(),B,BEnd);}
-int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
-int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
+int APT_PURE stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
+int APT_PURE stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
/* We assume that GCC 3 indicates that libstdc++3 is in use too. In that
case the definition of string::const_iterator is not the same as
const char * and we need these extra functions */
#if __GNUC__ >= 3
-int stringcmp(std::string::const_iterator A,std::string::const_iterator AEnd,
+int APT_PURE stringcmp(std::string::const_iterator A,std::string::const_iterator AEnd,
const char *B,const char *BEnd);
-int stringcmp(std::string::const_iterator A,std::string::const_iterator AEnd,
+int APT_PURE stringcmp(std::string::const_iterator A,std::string::const_iterator AEnd,
std::string::const_iterator B,std::string::const_iterator BEnd);
-int stringcasecmp(std::string::const_iterator A,std::string::const_iterator AEnd,
+int APT_PURE stringcasecmp(std::string::const_iterator A,std::string::const_iterator AEnd,
const char *B,const char *BEnd);
-int stringcasecmp(std::string::const_iterator A,std::string::const_iterator AEnd,
+int APT_PURE stringcasecmp(std::string::const_iterator A,std::string::const_iterator AEnd,
std::string::const_iterator B,std::string::const_iterator BEnd);
-inline int stringcmp(std::string::const_iterator A,std::string::const_iterator Aend,const char *B) {return stringcmp(A,Aend,B,B+strlen(B));};
-inline int stringcasecmp(std::string::const_iterator A,std::string::const_iterator Aend,const char *B) {return stringcasecmp(A,Aend,B,B+strlen(B));};
+inline APT_PURE int stringcmp(std::string::const_iterator A,std::string::const_iterator Aend,const char *B) {return stringcmp(A,Aend,B,B+strlen(B));}
+inline APT_PURE int stringcasecmp(std::string::const_iterator A,std::string::const_iterator Aend,const char *B) {return stringcasecmp(A,Aend,B,B+strlen(B));}
#endif
-APT_MKSTRCMP2(stringcmp,stringcmp);
-APT_MKSTRCMP2(stringcasecmp,stringcasecmp);
+APT_MKSTRCMP2(stringcmp,stringcmp)
+APT_MKSTRCMP2(stringcasecmp,stringcasecmp)
// Return the length of a NULL-terminated string array
-size_t strv_length(const char **str_array);
+size_t APT_PURE strv_length(const char **str_array);
-inline const char *DeNull(const char *s) {return (s == 0?"(null)":s);};
+inline const char *DeNull(const char *s) {return (s == 0?"(null)":s);}
class URI
{
@@ -159,13 +162,13 @@ class URI
unsigned int Port;
operator std::string();
- inline void operator =(const std::string &From) {CopyFrom(From);};
+ inline void operator =(const std::string &From) {CopyFrom(From);}
inline bool empty() {return Access.empty();};
static std::string SiteOnly(const std::string &URI);
static std::string NoUserPassword(const std::string &URI);
- URI(std::string Path) {CopyFrom(Path);};
- URI() : Port(0) {};
+ URI(std::string Path) {CopyFrom(Path);}
+ URI() : Port(0) {}
};
struct SubstVar