From 0d2e73c7aadad2b84ef19f2a37914c829a465573 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 22 Jan 2010 20:06:37 +0100 Subject: * apt-pkg/contrib/cdromutl.cc: - fix UnmountCdrom() fails, give it a bit more time and try the umount again --- apt-pkg/contrib/cdromutl.cc | 51 ++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 21 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc index 0cf9697ac..6dce82fe1 100644 --- a/apt-pkg/contrib/cdromutl.cc +++ b/apt-pkg/contrib/cdromutl.cc @@ -64,35 +64,44 @@ bool UnmountCdrom(string Path) { if (IsMounted(Path) == false) return true; - - int Child = ExecFork(); - // The child - if (Child == 0) + for (int i=0;i<3;i++) { - // Make all the fds /dev/null - for (int I = 0; I != 3; I++) - dup2(open("/dev/null",O_RDWR),I); + + int Child = ExecFork(); - if (_config->Exists("Acquire::cdrom::"+Path+"::UMount") == true) + // The child + if (Child == 0) { - if (system(_config->Find("Acquire::cdrom::"+Path+"::UMount").c_str()) != 0) + // Make all the fds /dev/null + for (int I = 0; I != 3; I++) + dup2(open("/dev/null",O_RDWR),I); + + if (_config->Exists("Acquire::cdrom::"+Path+"::UMount") == true) + { + if (system(_config->Find("Acquire::cdrom::"+Path+"::UMount").c_str()) != 0) + _exit(100); + _exit(0); + } + else + { + const char *Args[10]; + Args[0] = "umount"; + Args[1] = Path.c_str(); + Args[2] = 0; + execvp(Args[0],(char **)Args); _exit(100); - _exit(0); + } } - else - { - const char *Args[10]; - Args[0] = "umount"; - Args[1] = Path.c_str(); - Args[2] = 0; - execvp(Args[0],(char **)Args); - _exit(100); - } + + // if it can not be umounted, give it a bit more time + // this can happen when auto-mount magic or fs/cdrom prober attack + if (ExecWait(Child,"umount",true) == true) + return true; + sleep(1); } - // Wait for mount - return ExecWait(Child,"umount",true); + return false; } /*}}}*/ // MountCdrom - Mount a cdrom /*{{{*/ -- cgit v1.2.3 From b39c18596d05cea1b3c0f0445b17080e9a2e4c19 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sat, 23 Jan 2010 00:37:21 +0100 Subject: * apt-pkg/contrib/fileutl.cc: - Fix the newly introduced method GetListOfFilesInDir to not accept every file if no extension is enforced (= restore old behaviour). (Closes: #565213) * apt-pkg/policy.cc: - accept also partfiles with "pref" file extension as valid * apt-pkg/contrib/configuration.cc: - accept also partfiles with "conf" file extension as valid * doc/apt.conf.5.xml: - reorder description and split out syntax - add partfile name convention (Closes: #558348) * doc/apt_preferences.conf.5.xml: - describe partfile name convention also here * apt-pkg/deb/dpkgpm.cc: - don't segfault if term.log file can't be opened. Thanks Sam Brightman for the patch! (Closes: #475770) * doc/*: - replace the per language addendum with a global addendum - add a explanation why translations include (maybe) english parts to the new global addendum (Closes: #561636) * apt-pkg/contrib/strutl.cc: - fix malloc asseration fail with ja_JP.eucJP locale in apt-cache search. Thanks Kusanagi Kouichi! (Closes: #548884) --- apt-pkg/contrib/configuration.cc | 2 +- apt-pkg/contrib/error.h | 10 +++-- apt-pkg/contrib/fileutl.cc | 84 +++++++++++++++++++++++++++++++++++++--- apt-pkg/contrib/fileutl.h | 5 +++ apt-pkg/contrib/strutl.cc | 49 +++++++++++++++-------- apt-pkg/contrib/system.h | 22 +++++++++++ apt-pkg/deb/dpkgpm.cc | 7 ++-- apt-pkg/policy.cc | 2 +- 8 files changed, 151 insertions(+), 30 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index aaa669ffc..8e3b84499 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -832,7 +832,7 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool AsSectional, bool ReadConfigDir(Configuration &Conf,const string &Dir, bool AsSectional, unsigned Depth) { - vector const List = GetListOfFilesInDir(Dir, "", true); + vector const List = GetListOfFilesInDir(Dir, "conf", true, true); // Read the files for (vector::const_iterator I = List.begin(); I != List.end(); I++) diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h index a3be6a575..86aa9eca3 100644 --- a/apt-pkg/contrib/error.h +++ b/apt-pkg/contrib/error.h @@ -53,6 +53,8 @@ #include +#include + using std::string; class GlobalError @@ -71,13 +73,13 @@ class GlobalError public: // Call to generate an error from a library call. - bool Errno(const char *Function,const char *Description,...) APT_MFORMAT2; - bool WarningE(const char *Function,const char *Description,...) APT_MFORMAT2; + bool Errno(const char *Function,const char *Description,...) APT_MFORMAT2 __cold; + bool WarningE(const char *Function,const char *Description,...) APT_MFORMAT2 __cold; /* A warning should be considered less severe than an error, and may be ignored by the client. */ - bool Error(const char *Description,...) APT_MFORMAT1; - bool Warning(const char *Description,...) APT_MFORMAT1; + bool Error(const char *Description,...) APT_MFORMAT1 __cold; + bool Warning(const char *Description,...) APT_MFORMAT1 __cold; // Simple accessors inline bool PendingError() {return PendingFlag;}; diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index cce8a4512..da32983f1 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -202,8 +202,37 @@ bool FileExists(string File) /* If an extension is given only files with this extension are included in the returned vector, otherwise every "normal" file is included. */ std::vector GetListOfFilesInDir(string const &Dir, string const &Ext, - bool const &SortList) + bool const &SortList) { + return GetListOfFilesInDir(Dir, Ext, SortList, false); +} +std::vector GetListOfFilesInDir(string const &Dir, string const &Ext, + bool const &SortList, bool const &AllowNoExt) +{ + std::vector ext; + ext.reserve(2); + if (Ext.empty() == false) + ext.push_back(Ext); + if (AllowNoExt == true && ext.empty() == false) + ext.push_back(""); + return GetListOfFilesInDir(Dir, ext, SortList); +} +std::vector GetListOfFilesInDir(string const &Dir, std::vector const &Ext, + bool const &SortList) +{ + // Attention debuggers: need to be set with the environment config file! + bool const Debug = _config->FindB("Debug::GetListOfFilesInDir", false); + if (Debug == true) + { + std::clog << "Accept in " << Dir << " only files with the following " << Ext.size() << " extensions:" << std::endl; + if (Ext.empty() == true) + std::clog << "\tNO extension" << std::endl; + else + for (std::vector::const_iterator e = Ext.begin(); + e != Ext.end(); ++e) + std::clog << '\t' << (e->empty() == true ? "NO" : *e) << " extension" << std::endl; + } + std::vector List; DIR *D = opendir(Dir.c_str()); if (D == 0) @@ -214,28 +243,73 @@ std::vector GetListOfFilesInDir(string const &Dir, string const &Ext, for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D)) { + // skip "hidden" files if (Ent->d_name[0] == '.') continue; - if (Ext.empty() == false && flExtension(Ent->d_name) != Ext) - continue; + // check for accepted extension: + // no extension given -> periods are bad as hell! + // extensions given -> "" extension allows no extension + if (Ext.empty() == false) + { + string d_ext = flExtension(Ent->d_name); + if (d_ext == Ent->d_name) // no extension + { + if (std::find(Ext.begin(), Ext.end(), "") == Ext.end()) + { + if (Debug == true) + std::clog << "Bad file: " << Ent->d_name << " → no extension" << std::endl; + continue; + } + } + else if (std::find(Ext.begin(), Ext.end(), d_ext) == Ext.end()) + { + if (Debug == true) + std::clog << "Bad file: " << Ent->d_name << " → bad extension »" << flExtension(Ent->d_name) << "«" << std::endl; + continue; + } + } - // Skip bad file names ala run-parts + // Skip bad filenames ala run-parts const char *C = Ent->d_name; for (; *C != 0; ++C) if (isalpha(*C) == 0 && isdigit(*C) == 0 - && *C != '_' && *C != '-' && *C != '.') + && *C != '_' && *C != '-') { + // no required extension -> dot is a bad character + if (*C == '.' && Ext.empty() == false) + continue; break; + } + // we don't reach the end of the name -> bad character included if (*C != 0) + { + if (Debug == true) + std::clog << "Bad file: " << Ent->d_name << " → bad character »" + << *C << "« in filename (period allowed: " << (Ext.empty() ? "no" : "yes") << ")" << std::endl; continue; + } + + // skip filenames which end with a period. These are never valid + if (*(C - 1) == '.') + { + if (Debug == true) + std::clog << "Bad file: " << Ent->d_name << " → Period as last character" << std::endl; + continue; + } // Make sure it is a file and not something else string const File = flCombine(Dir,Ent->d_name); struct stat St; if (stat(File.c_str(),&St) != 0 || S_ISREG(St.st_mode) == 0) + { + if (Debug == true) + std::clog << "Bad file: " << Ent->d_name << " → stat says not a good file" << std::endl; continue; + } + if (Debug == true) + std::clog << "Accept file: " << Ent->d_name << " in " << Dir << std::endl; List.push_back(File); } closedir(D); diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 2807c29d9..85a94898c 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -82,8 +82,13 @@ bool RunScripts(const char *Cnf); bool CopyFile(FileFd &From,FileFd &To); int GetLock(string File,bool Errors = true); bool FileExists(string File); +// FIXME: next ABI-Break: merge the two method-headers std::vector GetListOfFilesInDir(string const &Dir, string const &Ext, bool const &SortList); +std::vector GetListOfFilesInDir(string const &Dir, string const &Ext, + bool const &SortList, bool const &AllowNoExt); +std::vector GetListOfFilesInDir(string const &Dir, std::vector const &Ext, + bool const &SortList); string SafeGetCWD(); void SetCloseExec(int Fd,bool Close); void SetNonBlock(int Fd,bool Block); diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 4c05f2df8..2913fbf44 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -43,9 +43,10 @@ bool UTF8ToCodeset(const char *codeset, const string &orig, string *dest) { iconv_t cd; const char *inbuf; - char *inptr, *outbuf, *outptr; - size_t insize, outsize; - + char *inptr, *outbuf; + size_t insize, bufsize; + dest->clear(); + cd = iconv_open(codeset, "UTF-8"); if (cd == (iconv_t)(-1)) { // Something went wrong @@ -55,33 +56,49 @@ bool UTF8ToCodeset(const char *codeset, const string &orig, string *dest) else perror("iconv_open"); - // Clean the destination string - *dest = ""; - return false; } - insize = outsize = orig.size(); + insize = bufsize = orig.size(); inbuf = orig.data(); inptr = (char *)inbuf; - outbuf = new char[insize+1]; - outptr = outbuf; + outbuf = new char[bufsize]; + size_t lastError = -1; while (insize != 0) { + char *outptr = outbuf; + size_t outsize = bufsize; size_t const err = iconv(cd, &inptr, &insize, &outptr, &outsize); + dest->append(outbuf, outptr - outbuf); if (err == (size_t)(-1)) { - insize--; - outsize++; - inptr++; - *outptr = '?'; - outptr++; + switch (errno) + { + case EILSEQ: + insize--; + inptr++; + // replace a series of unknown multibytes with a single "?" + if (lastError != insize) { + lastError = insize - 1; + dest->append("?"); + } + break; + case EINVAL: + insize = 0; + break; + case E2BIG: + if (outptr == outbuf) + { + bufsize *= 2; + delete[] outbuf; + outbuf = new char[bufsize]; + } + break; + } } } - *outptr = '\0'; - *dest = outbuf; delete[] outbuf; iconv_close(cd); diff --git a/apt-pkg/contrib/system.h b/apt-pkg/contrib/system.h index 7ec3d7feb..b57093b93 100644 --- a/apt-pkg/contrib/system.h +++ b/apt-pkg/contrib/system.h @@ -55,4 +55,26 @@ #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)) + /* likely() and unlikely() can be used to mark boolean expressions + as (not) likely true which will help the compiler to optimise */ + #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 likely(x) (x) + #define unlikely(x) (x) +#endif + +// cold functions are unlikely() to be called +#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4 + #define __cold __attribute__ ((__cold__)) +#else + #define __cold /* no cold marker */ +#endif + #endif diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index d1a275a47..565f01b84 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -561,15 +561,16 @@ bool pkgDPkgPM::OpenLog() if (!logfile_name.empty()) { term_out = fopen(logfile_name.c_str(),"a"); + if (term_out == NULL) + return _error->WarningE(_("Could not open file '%s'"), logfile_name.c_str()); + chmod(logfile_name.c_str(), 0600); // output current time char outstr[200]; time_t t = time(NULL); struct tm *tmp = localtime(&t); strftime(outstr, sizeof(outstr), "%F %T", tmp); - fprintf(term_out, "\nLog started: "); - fprintf(term_out, "%s", outstr); - fprintf(term_out, "\n"); + fprintf(term_out, "\nLog started: %s\n", outstr); } return true; } diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc index 393181b6d..f9901bc9a 100644 --- a/apt-pkg/policy.cc +++ b/apt-pkg/policy.cc @@ -280,7 +280,7 @@ bool ReadPinDir(pkgPolicy &Plcy,string Dir) return true; } - vector const List = GetListOfFilesInDir(Dir, "", true); + vector const List = GetListOfFilesInDir(Dir, "pref", true, true); // Read the files for (vector::const_iterator I = List.begin(); I != List.end(); I++) -- cgit v1.2.3 From 93adae194b5db00e3afb8fe89b907eed9df28763 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 27 Jan 2010 12:11:07 +0100 Subject: merge 1695..1701 from the lp:~mvo/apt/mvo branch --- apt-pkg/cdrom.cc | 5 ++--- apt-pkg/init.cc | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index 72d8e4d41..96d4e9c91 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -829,8 +829,6 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/ } } - - // Unmount and finish if (_config->FindB("APT::CDROM::NoMount",false) == false) { log->Update(_("Unmounting CD-ROM...\n"), STEP_LAST); @@ -921,6 +919,7 @@ pkgUdevCdromDevices::Scan() /*{{{*/ pkgUdevCdromDevices::~pkgUdevCdromDevices() /*{{{*/ { - dlclose(libudev_handle); + if (libudev_handle != NULL) + dlclose(libudev_handle); } /*}}}*/ diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc index a54c09a36..d8c201b9d 100644 --- a/apt-pkg/init.cc +++ b/apt-pkg/init.cc @@ -65,11 +65,12 @@ bool pkgInitConfig(Configuration &Cnf) Cnf.Set("Dir::Etc::vendorlist","vendors.list"); Cnf.Set("Dir::Etc::vendorparts","vendors.list.d"); Cnf.Set("Dir::Etc::main","apt.conf"); - Cnf.Set("Dir::ETc::netrc", "auth.conf"); + Cnf.Set("Dir::Etc::netrc", "auth.conf"); Cnf.Set("Dir::Etc::parts","apt.conf.d"); Cnf.Set("Dir::Etc::preferences","preferences"); Cnf.Set("Dir::Etc::preferencesparts","preferences.d"); Cnf.Set("Dir::Bin::methods","/usr/lib/apt/methods"); + Cnf.Set("Dir::Media::MountPath","/media/apt"); // State Cnf.Set("Dir::Log","var/log/apt"); -- cgit v1.2.3 From 2893f7b5ec6b2220ccfca6b9648482a6df926eca Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sun, 31 Jan 2010 07:28:06 -0800 Subject: * cmdline/acqprogress.cc: - Set Mode to Medium so that the correct prefix is used. Thanks Stefan Haller for the patch! (Closes: #567304 LP: #275243) * ftparchive/writer.cc: - generate sha1 and sha256 checksums for dsc (Closes: #567343) * cmdline/apt-get.cc: - don't mark as manually if in download only (Closes: #468180) --- apt-pkg/contrib/error.h | 30 +++++++----------------------- apt-pkg/contrib/system.h | 9 +++++++++ 2 files changed, 16 insertions(+), 23 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h index 86aa9eca3..90747ff7e 100644 --- a/apt-pkg/contrib/error.h +++ b/apt-pkg/contrib/error.h @@ -40,28 +40,15 @@ #ifndef PKGLIB_ERROR_H #define PKGLIB_ERROR_H +#include - -#ifdef __GNUG__ -// Methods have a hidden this parameter that is visible to this attribute -#define APT_MFORMAT1 __attribute__ ((format (printf, 2, 3))) -#define APT_MFORMAT2 __attribute__ ((format (printf, 3, 4))) -#else -#define APT_MFORMAT1 -#define APT_MFORMAT2 -#endif - #include -#include - -using std::string; - class GlobalError { struct Item { - string Text; + std::string Text; bool Error; Item *Next; }; @@ -73,18 +60,18 @@ class GlobalError public: // Call to generate an error from a library call. - bool Errno(const char *Function,const char *Description,...) APT_MFORMAT2 __cold; - bool WarningE(const char *Function,const char *Description,...) APT_MFORMAT2 __cold; + bool Errno(const char *Function,const char *Description,...) __like_printf_2 __cold; + bool WarningE(const char *Function,const char *Description,...) __like_printf_2 __cold; /* A warning should be considered less severe than an error, and may be ignored by the client. */ - bool Error(const char *Description,...) APT_MFORMAT1 __cold; - bool Warning(const char *Description,...) APT_MFORMAT1 __cold; + bool Error(const char *Description,...) __like_printf_1 __cold; + bool Warning(const char *Description,...) __like_printf_1 __cold; // Simple accessors inline bool PendingError() {return PendingFlag;}; inline bool empty() {return List == 0;}; - bool PopMessage(string &Text); + bool PopMessage(std::string &Text); void Discard(); // Usefull routine to dump to cerr @@ -97,7 +84,4 @@ class GlobalError GlobalError *_GetErrorObj(); #define _error _GetErrorObj() -#undef APT_MFORMAT1 -#undef APT_MFORMAT2 - #endif diff --git a/apt-pkg/contrib/system.h b/apt-pkg/contrib/system.h index b57093b93..a0580b218 100644 --- a/apt-pkg/contrib/system.h +++ b/apt-pkg/contrib/system.h @@ -77,4 +77,13 @@ #define __cold /* no cold marker */ #endif +#ifdef __GNUG__ +// Methods have a hidden this parameter that is visible to this attribute + #define __like_printf_1 __attribute__ ((format (printf, 2, 3))) + #define __like_printf_2 __attribute__ ((format (printf, 3, 4))) +#else + #define __like_printf_1 + #define __like_printf_2 +#endif + #endif -- cgit v1.2.3 From aea7f4c877f3091180ad5f418793f796bb82f255 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sun, 31 Jan 2010 18:56:26 -0800 Subject: merge r1966..1967 from lp:~donkult/apt/sid --- apt-pkg/contrib/hashes.cc | 4 +- apt-pkg/contrib/macros.h | 88 +++++++++++++++++++++++++++++++++++++++++++ apt-pkg/contrib/md5.cc | 3 +- apt-pkg/contrib/sha1.cc | 2 +- apt-pkg/contrib/system.h | 89 -------------------------------------------- apt-pkg/deb/deblistparser.cc | 3 +- apt-pkg/makefile | 6 +-- apt-pkg/pkgcache.cc | 1 - apt-pkg/pkgcachegen.cc | 2 +- 9 files changed, 96 insertions(+), 102 deletions(-) create mode 100644 apt-pkg/contrib/macros.h delete mode 100644 apt-pkg/contrib/system.h (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc index b43771ea7..985d89d90 100644 --- a/apt-pkg/contrib/hashes.cc +++ b/apt-pkg/contrib/hashes.cc @@ -14,9 +14,9 @@ #include #include #include - +#include + #include -#include #include #include /*}}}*/ diff --git a/apt-pkg/contrib/macros.h b/apt-pkg/contrib/macros.h new file mode 100644 index 000000000..9aeb77b81 --- /dev/null +++ b/apt-pkg/contrib/macros.h @@ -0,0 +1,88 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/* ###################################################################### + + Macros Header - Various useful macro definitions + + This source is placed in the Public Domain, do with it what you will + It was originally written by Brian C. White. + + ##################################################################### */ + /*}}}*/ +// Private header +#ifndef MACROS_H +#define MACROS_H + +// MIN_VAL(SINT16) will return -0x8000 and MAX_VAL(SINT16) = 0x7FFF +#define MIN_VAL(t) (((t)(-1) > 0) ? (t)( 0) : (t)(((1L<<(sizeof(t)*8-1)) ))) +#define MAX_VAL(t) (((t)(-1) > 0) ? (t)(-1) : (t)(((1L<<(sizeof(t)*8-1))-1))) + +// Min/Max functions +#if !defined(MIN) +#if defined(__HIGHC__) +#define MIN(x,y) _min(x,y) +#define MAX(x,y) _max(x,y) +#endif + +// GNU C++ has a min/max operator +#if defined(__GNUG__) +#define MIN(A,B) ((A) ? (B)) +#endif + +/* Templates tend to mess up existing code that uses min/max because of the + strict matching requirements */ +#if !defined(MIN) +#define MIN(A,B) ((A) < (B)?(A):(B)) +#define MAX(A,B) ((A) > (B)?(A):(B)) +#endif +#endif + +/* Bound functions, bound will return the value b within the limits a-c + bounv will change b so that it is within the limits of a-c. */ +#define _bound(a,b,c) MIN(c,MAX(b,a)) +#define _boundv(a,b,c) b = _bound(a,b,c) +#define ABS(a) (((a) < (0)) ?-(a) : (a)) + +/* Usefull count macro, use on an array of things and it will return the + number of items in the array */ +#define _count(a) (sizeof(a)/sizeof(a[0])) + +// Flag Macros +#define FLAG(f) (1L << (f)) +#define SETFLAG(v,f) ((v) |= FLAG(f)) +#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)) + /* likely() and unlikely() can be used to mark boolean expressions + as (not) likely true which will help the compiler to optimise */ + #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 likely(x) (x) + #define unlikely(x) (x) +#endif + +// cold functions are unlikely() to be called +#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4 + #define __cold __attribute__ ((__cold__)) +#else + #define __cold /* no cold marker */ +#endif + +#ifdef __GNUG__ +// Methods have a hidden this parameter that is visible to this attribute + #define __like_printf_1 __attribute__ ((format (printf, 2, 3))) + #define __like_printf_2 __attribute__ ((format (printf, 3, 4))) +#else + #define __like_printf_1 + #define __like_printf_2 +#endif + +#endif diff --git a/apt-pkg/contrib/md5.cc b/apt-pkg/contrib/md5.cc index 2bfd70f1b..c0fa8493d 100644 --- a/apt-pkg/contrib/md5.cc +++ b/apt-pkg/contrib/md5.cc @@ -37,14 +37,13 @@ // Include Files /*{{{*/ #include #include +#include #include #include #include // For htonl #include #include -#include - /*}}}*/ // byteSwap - Swap bytes in a buffer /*{{{*/ diff --git a/apt-pkg/contrib/sha1.cc b/apt-pkg/contrib/sha1.cc index b70f31dc6..eae52d52f 100644 --- a/apt-pkg/contrib/sha1.cc +++ b/apt-pkg/contrib/sha1.cc @@ -31,12 +31,12 @@ // Include Files /*{{{*/ #include #include +#include #include #include #include #include -#include /*}}}*/ // SHA1Transform - Alters an existing SHA-1 hash /*{{{*/ diff --git a/apt-pkg/contrib/system.h b/apt-pkg/contrib/system.h deleted file mode 100644 index a0580b218..000000000 --- a/apt-pkg/contrib/system.h +++ /dev/null @@ -1,89 +0,0 @@ -// -*- mode: cpp; mode: fold -*- -// Description /*{{{*/ -// $Id: system.h,v 1.3 1999/12/10 23:40:29 jgg Exp $ -/* ###################################################################### - - System Header - Usefull private definitions - - This source is placed in the Public Domain, do with it what you will - It was originally written by Brian C. White. - - ##################################################################### */ - /*}}}*/ -// Private header -#ifndef SYSTEM_H -#define SYSTEM_H - -// MIN_VAL(SINT16) will return -0x8000 and MAX_VAL(SINT16) = 0x7FFF -#define MIN_VAL(t) (((t)(-1) > 0) ? (t)( 0) : (t)(((1L<<(sizeof(t)*8-1)) ))) -#define MAX_VAL(t) (((t)(-1) > 0) ? (t)(-1) : (t)(((1L<<(sizeof(t)*8-1))-1))) - -// Min/Max functions -#if !defined(MIN) -#if defined(__HIGHC__) -#define MIN(x,y) _min(x,y) -#define MAX(x,y) _max(x,y) -#endif - -// GNU C++ has a min/max operator -#if defined(__GNUG__) -#define MIN(A,B) ((A) ? (B)) -#endif - -/* Templates tend to mess up existing code that uses min/max because of the - strict matching requirements */ -#if !defined(MIN) -#define MIN(A,B) ((A) < (B)?(A):(B)) -#define MAX(A,B) ((A) > (B)?(A):(B)) -#endif -#endif - -/* Bound functions, bound will return the value b within the limits a-c - bounv will change b so that it is within the limits of a-c. */ -#define _bound(a,b,c) MIN(c,MAX(b,a)) -#define _boundv(a,b,c) b = _bound(a,b,c) -#define ABS(a) (((a) < (0)) ?-(a) : (a)) - -/* Usefull count macro, use on an array of things and it will return the - number of items in the array */ -#define _count(a) (sizeof(a)/sizeof(a[0])) - -// Flag Macros -#define FLAG(f) (1L << (f)) -#define SETFLAG(v,f) ((v) |= FLAG(f)) -#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)) - /* likely() and unlikely() can be used to mark boolean expressions - as (not) likely true which will help the compiler to optimise */ - #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 likely(x) (x) - #define unlikely(x) (x) -#endif - -// cold functions are unlikely() to be called -#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4 - #define __cold __attribute__ ((__cold__)) -#else - #define __cold /* no cold marker */ -#endif - -#ifdef __GNUG__ -// Methods have a hidden this parameter that is visible to this attribute - #define __like_printf_1 __attribute__ ((format (printf, 2, 3))) - #define __like_printf_2 __attribute__ ((format (printf, 3, 4))) -#else - #define __like_printf_1 - #define __like_printf_2 -#endif - -#endif diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 517b771a5..25b0953e0 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -16,10 +16,9 @@ #include #include #include +#include #include - -#include /*}}}*/ static debListParser::WordList PrioList[] = {{"important",pkgCache::State::Important}, diff --git a/apt-pkg/makefile b/apt-pkg/makefile index 3d6209658..bdd49c089 100644 --- a/apt-pkg/makefile +++ b/apt-pkg/makefile @@ -24,7 +24,8 @@ SOURCE = contrib/mmap.cc contrib/error.cc contrib/strutl.cc \ contrib/cdromutl.cc contrib/crc-16.cc contrib/netrc.cc \ contrib/fileutl.cc HEADERS = mmap.h error.h configuration.h fileutl.h cmndline.h netrc.h\ - md5.h crc-16.h cdromutl.h strutl.h sptr.h sha1.h sha256.h hashes.h + md5.h crc-16.h cdromutl.h strutl.h sptr.h sha1.h sha256.h hashes.h \ + macros.h # Source code for the core main library SOURCE+= pkgcache.cc version.cc depcache.cc \ @@ -53,7 +54,4 @@ HEADERS+= debversion.h debsrcrecords.h dpkgpm.h debrecords.h \ HEADERS := $(addprefix apt-pkg/,$(HEADERS)) -# Private header files -HEADERS+= system.h - include $(LIBRARY_H) diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index e8ee75b96..4a0f3ee58 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -35,7 +35,6 @@ #include #include -#include /*}}}*/ using std::string; diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index f988c1018..3eeb18cae 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -32,7 +33,6 @@ #include #include #include -#include /*}}}*/ typedef vector::iterator FileIterator; -- cgit v1.2.3