X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/7f25bdff3a0fa55ba897964d5c82475b45f3325a..d89df07a5915bbee7d7a57983a83dfb284c0895c:/apt-pkg/contrib/strutl.cc diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 6a90b2b88..a6eaeaa79 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.17 1999/01/18 06:20:08 jgg Exp $ +// $Id: strutl.cc,v 1.23 1999/03/16 07:27:17 jgg Exp $ /* ###################################################################### String Util - Some usefull string functions. @@ -16,15 +16,17 @@ /*}}}*/ // Includes /*{{{*/ #ifdef __GNUG__ -#pragma implementation "strutl.h" +#pragma implementation "apt-pkg/strutl.h" #endif -#include +#include #include #include #include #include +#include +#include /*}}}*/ // strstrip - Remove white space from the front and back of a string /*{{{*/ @@ -116,7 +118,7 @@ bool ParseQuoteWord(const char *&String,string &Res) { Tmp[0] = Start[1]; Tmp[1] = Start[2]; - Tmp[3] = 0; + Tmp[2] = 0; *I = (char)strtol(Tmp,0,16); Start += 3; continue; @@ -198,6 +200,31 @@ string QuoteString(string Str,const char *Bad) return Res; } /*}}}*/ +// DeQuoteString - Convert a string from quoted from /*{{{*/ +// --------------------------------------------------------------------- +/* This undoes QuoteString */ +string DeQuoteString(string Str) +{ + string Res; + for (string::iterator I = Str.begin(); I != Str.end(); I++) + { + if (*I == '%' && I + 2 < Str.end()) + { + char Tmp[3]; + Tmp[0] = I[1]; + Tmp[1] = I[2]; + Tmp[2] = 0; + Res += (char)strtol(Tmp,0,16); + I += 2; + continue; + } + else + Res += *I; + } + return Res; +} + + /*}}}*/ // SizeToStr - Convert a long into a human readable size /*{{{*/ // --------------------------------------------------------------------- /* A max of 4 digits are shown before conversion to the next highest unit. @@ -503,6 +530,8 @@ bool ReadMessages(int Fd, vector &List) while (1) { int Res = read(Fd,End,sizeof(Buffer) - (End-Buffer)); + if (Res < 0 && errno == EINTR) + continue; // Process is dead, this is kind of bad.. if (Res == 0) @@ -572,6 +601,30 @@ static int MonthConv(char *Month) } } /*}}}*/ +// timegm - Internal timegm function if gnu is not available /*{{{*/ +// --------------------------------------------------------------------- +/* Ripped this evil little function from wget - I prefer the use of + GNU timegm if possible as this technique will have interesting problems + with leap seconds, timezones and other. + + Converts struct tm to time_t, assuming the data in tm is UTC rather + than local timezone (mktime assumes the latter). + + Contributed by Roger Beeman , with the help of + Mark Baushke and the rest of the Gurus at CISCO. */ +#ifndef __USE_MISC // glib sets this +static time_t timegm(struct tm *t) +{ + time_t tl, tb; + + tl = mktime (t); + if (tl == -1) + return -1; + tb = mktime (gmtime (&tl)); + return (tl <= tb ? (tl + (tl - tb)) : (tl - (tb - tl))); +} +#endif + /*}}}*/ // StrToTime - Converts a string into a time_t /*{{{*/ // --------------------------------------------------------------------- /* This handles all 3 populare time formats including RFC 1123, RFC 1036