summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorArch Librarian <arch@canonical.com>2004-09-20 16:53:03 +0000
committerArch Librarian <arch@canonical.com>2004-09-20 16:53:03 +0000
commit6d5dd02a49b18017c296c2d76bc6bb1d9f1ef6ac (patch)
tree109a3da8b5af3304fdc9d2e9f753edb611e54b95 /apt-pkg/contrib
parent10861bb5068971efe4de96e679a711ab45bb3e25 (diff)
Minor fixes for FTP support
Author: jgg Date: 1999-03-15 08:10:39 GMT Minor fixes for FTP support
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/configuration.h4
-rw-r--r--apt-pkg/contrib/fileutl.cc23
-rw-r--r--apt-pkg/contrib/fileutl.h3
-rw-r--r--apt-pkg/contrib/strutl.cc71
4 files changed, 72 insertions, 29 deletions
diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h
index adda854cb..bf99f07c2 100644
--- a/apt-pkg/contrib/configuration.h
+++ b/apt-pkg/contrib/configuration.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: configuration.h,v 1.9 1999/01/18 06:20:07 jgg Exp $
+// $Id: configuration.h,v 1.10 1999/03/15 08:10:39 jgg Exp $
/* ######################################################################
Configuration Class
@@ -60,7 +60,9 @@ class Configuration
string FindFile(const char *Name,const char *Default = 0);
string FindDir(const char *Name,const char *Default = 0);
int FindI(const char *Name,int Default = 0);
+ int FindI(string Name,bool Default = 0) {return FindI(Name.c_str(),Default);};
bool FindB(const char *Name,bool Default = false);
+ bool FindB(string Name,bool Default = false) {return FindB(Name.c_str(),Default);};
inline void Set(string Name,string Value) {Set(Name.c_str(),Value);};
void Set(const char *Name,string Value);
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index b6a64926d..a761794ee 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: fileutl.cc,v 1.21 1999/02/16 04:18:35 jgg Exp $
+// $Id: fileutl.cc,v 1.22 1999/03/15 08:10:39 jgg Exp $
/* ######################################################################
File Utilities
@@ -164,15 +164,16 @@ void SetNonBlock(int Fd,bool Block)
// WaitFd - Wait for a FD to become readable /*{{{*/
// ---------------------------------------------------------------------
/* This waits for a FD to become readable using select. It is usefull for
- applications making use of non-blocking sockets. */
+ applications making use of non-blocking sockets. The timeout is
+ in seconds. */
bool WaitFd(int Fd,bool write,unsigned long timeout)
{
fd_set Set;
struct timeval tv;
FD_ZERO(&Set);
FD_SET(Fd,&Set);
- tv.tv_sec = timeout / 1000000;
- tv.tv_usec = timeout % 1000000;
+ tv.tv_sec = timeout;
+ tv.tv_usec = 0;
if (write == true)
{
if (select(Fd+1,0,&Set,0,(timeout != 0?&tv:0)) <= 0)
@@ -278,6 +279,20 @@ bool FileFd::Seek(unsigned long To)
return true;
}
/*}}}*/
+// FileFd::Truncate - Truncate the file /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool FileFd::Truncate(unsigned long To)
+{
+ if (ftruncate(iFd,To) != 0)
+ {
+ Flags |= Fail;
+ return _error->Error("Unable to truncate to %u",To);
+ }
+
+ return true;
+}
+ /*}}}*/
// FileFd::Tell - Current seek position /*{{{*/
// ---------------------------------------------------------------------
/* */
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index 7bb3fc446..1bcb263c5 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: fileutl.h,v 1.14 1999/02/16 04:18:35 jgg Exp $
+// $Id: fileutl.h,v 1.15 1999/03/15 08:10:39 jgg Exp $
/* ######################################################################
File Utilities
@@ -42,6 +42,7 @@ class FileFd
bool Read(void *To,unsigned long Size);
bool Write(const void *From,unsigned long Size);
bool Seek(unsigned long To);
+ bool Truncate(unsigned long To);
unsigned long Tell();
unsigned long Size();
bool Close();
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index eb3ef96a2..a2464c9a3 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.20 1999/02/27 22:29:11 jgg Exp $
+// $Id: strutl.cc,v 1.21 1999/03/15 08:10:39 jgg Exp $
/* ######################################################################
String Util - Some usefull string functions.
@@ -20,7 +20,7 @@
#endif
#include <apt-pkg/strutl.h>
-#include <apt-pkg/fileutl.h>
+#include <apt-pkg//fileutl.h>
#include <ctype.h>
#include <string.h>
@@ -178,23 +178,20 @@ bool ParseCWord(const char *String,string &Res)
return true;
}
/*}}}*/
-// DeQuoteString - Convert a string from quoted from /*{{{*/
+// QuoteString - Convert a string into quoted from /*{{{*/
// ---------------------------------------------------------------------
-/* This undoes QuoteString */
-string DeQuoteString(string Str)
+/* */
+string QuoteString(string Str,const char *Bad)
{
string Res;
for (string::iterator I = Str.begin(); I != Str.end(); I++)
{
- if (*I == '%' && I + 2 < Str.end())
+ if (strchr(Bad,*I) != 0 || isprint(*I) == 0 ||
+ *I <= 0x20 || *I >= 0x7F)
{
- char Tmp[3];
- Tmp[0] = I[1];
- Tmp[1] = I[2];
- Tmp[2] = 0;
- Res += (char)strtol(Tmp,0,16);
- I += 2;
- continue;
+ char Buf[10];
+ sprintf(Buf,"%%%02x",(int)*I);
+ Res += Buf;
}
else
Res += *I;
@@ -202,27 +199,31 @@ string DeQuoteString(string Str)
return Res;
}
/*}}}*/
-// QuoteString - Convert a string into quoted from /*{{{*/
+// DeQuoteString - Convert a string from quoted from /*{{{*/
// ---------------------------------------------------------------------
-/* */
-string QuoteString(string Str,const char *Bad)
+/* This undoes QuoteString */
+string DeQuoteString(string Str)
{
string Res;
for (string::iterator I = Str.begin(); I != Str.end(); I++)
{
- if (strchr(Bad,*I) != 0 || isprint(*I) == 0 ||
- *I <= 0x20 || *I >= 0x7F)
+ if (*I == '%' && I + 2 < Str.end())
{
- char Buf[10];
- sprintf(Buf,"%%%02x",(int)*I);
- Res += Buf;
+ 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;
+ 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.
@@ -597,6 +598,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 <beeman@cisco.com>, with the help of
+ Mark Baushke <mdb@cisco.com> 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