X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/47db89970b749eb28a4fd616fc944c00b5153a62..22dcc318d978813b3c4d1ae1a1f41933d0e1d69b:/apt-pkg/contrib/strutl.cc diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 60a57b5c7..a75fbdf92 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: strutl.cc,v 1.42 2001/05/29 04:40:34 jgg Exp $ +// $Id: strutl.cc,v 1.48 2003/07/18 14:15:11 mdz Exp $ /* ###################################################################### String Util - Some useful string functions. @@ -33,6 +33,8 @@ #include #include +#include "config.h" + using namespace std; /*}}}*/ @@ -440,6 +442,8 @@ int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd) return -1; return 1; } + +#if __GNUC__ >= 3 int stringcmp(string::const_iterator A,string::const_iterator AEnd, const char *B,const char *BEnd) { @@ -474,6 +478,7 @@ int stringcmp(string::const_iterator A,string::const_iterator AEnd, return -1; return 1; } +#endif /*}}}*/ // stringcasecmp - Arbitary case insensitive string compare /*{{{*/ // --------------------------------------------------------------------- @@ -494,6 +499,7 @@ int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd) return -1; return 1; } +#if __GNUC__ >= 3 int stringcasecmp(string::const_iterator A,string::const_iterator AEnd, const char *B,const char *BEnd) { @@ -528,6 +534,7 @@ int stringcasecmp(string::const_iterator A,string::const_iterator AEnd, return -1; return 1; } +#endif /*}}}*/ // LookupTag - Lookup the value of a tag in a taged string /*{{{*/ // --------------------------------------------------------------------- @@ -617,7 +624,7 @@ string TimeRFC1123(time_t Date) fancy buffering is used. */ bool ReadMessages(int Fd, vector &List) { - char Buffer[4000]; + char Buffer[64000]; char *End = Buffer; while (1) @@ -645,7 +652,7 @@ bool ReadMessages(int Fd, vector &List) continue; // Pull the message out - string Message(Buffer,0,I-Buffer); + string Message(Buffer,I-Buffer); // Fix up the buffer for (; I < End && *I == '\n'; I++); @@ -707,7 +714,11 @@ static int MonthConv(char *Month) Contributed by Roger Beeman , with the help of Mark Baushke and the rest of the Gurus at CISCO. */ -#ifndef __USE_MISC // glib sets this + +/* Turned it into an autoconf check, because GNU is not the only thing which + can provide timegm. -- 2002-09-22, Joel Baker */ + +#ifndef HAVE_TIMEGM // Now with autoconf! static time_t timegm(struct tm *t) { time_t tl, tb; @@ -935,8 +946,8 @@ unsigned long RegexChoice(RxChoiceList *Rxs,const char **ListBegin, /*}}}*/ // ioprintf - C format string outputter to C++ iostreams /*{{{*/ // --------------------------------------------------------------------- -/* This is used to make the internationalization strinc easier to translate - and to allow reordering of parameters */ +/* This is used to make the internationalization strings easier to translate + and to allow reordering of parameters */ void ioprintf(ostream &out,const char *format,...) { va_list args; @@ -948,6 +959,28 @@ void ioprintf(ostream &out,const char *format,...) out << S; } /*}}}*/ +// safe_snprintf - Safer snprintf /*{{{*/ +// --------------------------------------------------------------------- +/* This is a snprintf that will never (ever) go past 'End' and returns a + pointer to the end of the new string. The returned string is always null + terminated unless Buffer == end. This is a better alterantive to using + consecutive snprintfs. */ +char *safe_snprintf(char *Buffer,char *End,const char *Format,...) +{ + va_list args; + unsigned long Did; + + va_start(args,Format); + + if (End <= Buffer) + return End; + + Did = vsnprintf(Buffer,End - Buffer,Format,args); + if (Did < 0 || Buffer + Did > End) + return End; + return Buffer + Did; +} + /*}}}*/ // CheckDomainList - See if Host is in a , seperate list /*{{{*/ // --------------------------------------------------------------------- @@ -962,7 +995,7 @@ bool CheckDomainList(string Host,string List) continue; // Match the end of the string.. - if ((Host.size() >= (unsigned)(Cur - List.begin())) && + if ((Host.size() >= (unsigned)(Cur - Start)) && Cur - Start != 0 && stringcasecmp(Host.end() - (Cur - Start),Host.end(),Start,Cur) == 0) return true; @@ -1012,7 +1045,7 @@ void URI::CopyFrom(string U) Path = "/"; // Now we attempt to locate a user:pass@host fragment - if (FirstColon[1] == '/' && FirstColon[2] == '/') + if (FirstColon + 2 <= U.end() && FirstColon[1] == '/' && FirstColon[2] == '/') FirstColon += 3; else FirstColon += 1;