X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/6f27a7fc6c8471534c5cee39cffdc2def1388bdc..f8477782df203e1998a8704e71a1a3cc699e9e3a:/apt-pkg/contrib/error.cc diff --git a/apt-pkg/contrib/error.cc b/apt-pkg/contrib/error.cc index 42e01e9fe..5fe9bdfce 100644 --- a/apt-pkg/contrib/error.cc +++ b/apt-pkg/contrib/error.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: error.cc,v 1.4 1998/09/12 02:46:26 jgg Exp $ +// $Id: error.cc,v 1.11 2002/03/26 07:38:58 jgg Exp $ /* ###################################################################### Global Erorr Class - Global error mechanism @@ -20,20 +20,24 @@ #include +#include #include #include -#include +#include #include #include +#include "config.h" /*}}}*/ +using namespace std; + // Global Error Object /*{{{*/ /* If the implementation supports posix threads then the accessor function is compiled to be thread safe otherwise a non-safe version is used. A Per-Thread error object is maintained in much the same manner as libc manages errno */ -#if _POSIX_THREADS == 1 +#if defined(_POSIX_THREADS) && defined(HAVE_PTHREAD) #include static pthread_key_t ErrorKey; @@ -80,8 +84,9 @@ bool GlobalError::Errno(const char *Function,const char *Description,...) // sprintf the description char S[400]; - vsprintf(S,Description,args); - sprintf(S + strlen(S)," - %s (%i %s)",Function,errno,strerror(errno)); + vsnprintf(S,sizeof(S),Description,args); + snprintf(S + strlen(S),sizeof(S) - strlen(S), + " - %s (%i %s)",Function,errno,strerror(errno)); // Put it on the list Item *Itm = new Item; @@ -91,6 +96,32 @@ bool GlobalError::Errno(const char *Function,const char *Description,...) PendingFlag = true; + return false; +} + /*}}}*/ +// GlobalError::WarningE - Get part of the warn string from errno /*{{{*/ +// --------------------------------------------------------------------- +/* Function indicates the stdlib function that failed and Description is + a user string that leads the text. Form is: + Description - Function (errno: strerror) + Carefull of the buffer overrun, sprintf. + */ +bool GlobalError::WarningE(const char *Function,const char *Description,...) +{ + va_list args; + va_start(args,Description); + + // sprintf the description + char S[400]; + vsnprintf(S,sizeof(S),Description,args); + snprintf(S + strlen(S),sizeof(S) - strlen(S)," - %s (%i %s)",Function,errno,strerror(errno)); + + // Put it on the list + Item *Itm = new Item; + Itm->Text = S; + Itm->Error = false; + Insert(Itm); + return false; } /*}}}*/ @@ -104,7 +135,7 @@ bool GlobalError::Error(const char *Description,...) // sprintf the description char S[400]; - vsprintf(S,Description,args); + vsnprintf(S,sizeof(S),Description,args); // Put it on the list Item *Itm = new Item; @@ -127,7 +158,7 @@ bool GlobalError::Warning(const char *Description,...) // sprintf the description char S[400]; - vsprintf(S,Description,args); + vsnprintf(S,sizeof(S),Description,args); // Put it on the list Item *Itm = new Item;