summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2020-06-28 20:52:09 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2021-02-04 11:00:00 +0100
commit96dc40b19623621a9cc2c5541fb3adbbceb553b1 (patch)
tree405ed81b2c23d21b52324b393c25301056011162 /apt-pkg/contrib
parent35af71bc026d85aef4af979aa247e837d91dfc1c (diff)
Replace PrintStatus with SendMessage usage
varg API is a nightmare as the symbols seems different on ever other arch, but more importantly SendMessage does a few checks on the content of the message and it is all outputted via C++ iostreams and not mixed in FILE* which is handy for overriding the streams.
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/gpgv.cc15
-rw-r--r--apt-pkg/contrib/strutl.cc11
-rw-r--r--apt-pkg/contrib/strutl.h2
3 files changed, 7 insertions, 21 deletions
diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc
index 28f3150c3..3368ece84 100644
--- a/apt-pkg/contrib/gpgv.cc
+++ b/apt-pkg/contrib/gpgv.cc
@@ -121,21 +121,6 @@ static bool operator!=(LineBuffer const &buf, APT::StringView const exp) noexcep
And as a cherry on the cake, we use our apt-key wrapper to do part
of the lifting in regards to merging keyrings. Fun for the whole family.
*/
-static bool iovprintf(std::ostream &out, const char *format,
- va_list &args, ssize_t &size) {
- auto S = make_unique_char(malloc(size));
- ssize_t const n = vsnprintf(S.get(), size, format, args);
- if (n > -1 && n < size) {
- out << S.get();
- return true;
- } else {
- if (n > -1)
- size = n + 1;
- else
- size *= 2;
- }
- return false;
-}
static void APT_PRINTF(4) apt_error(std::ostream &outterm, int const statusfd, int fd[2], const char *format, ...)
{
std::ostringstream outstr;
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index 84e79122e..3a0a6eaa3 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -26,6 +26,7 @@
#include <limits>
#include <locale>
#include <sstream>
+#include <memory>
#include <sstream>
#include <string>
#include <vector>
@@ -1414,13 +1415,12 @@ unsigned long RegexChoice(RxChoiceList *Rxs,const char **ListBegin,
// ---------------------------------------------------------------------
/* This is used to make the internationalization strings easier to translate
and to allow reordering of parameters */
-static bool iovprintf(ostream &out, const char *format,
+bool iovprintf(std::ostream &out, const char *format,
va_list &args, ssize_t &size) {
- char *S = (char*)malloc(size);
- ssize_t const n = vsnprintf(S, size, format, args);
+ auto S = std::unique_ptr<char,decltype(&free)>{static_cast<char*>(malloc(size)), &free};
+ ssize_t const n = vsnprintf(S.get(), size, format, args);
if (n > -1 && n < size) {
- out << S;
- free(S);
+ out << S.get();
return true;
} else {
if (n > -1)
@@ -1428,7 +1428,6 @@ static bool iovprintf(ostream &out, const char *format,
else
size *= 2;
}
- free(S);
return false;
}
void ioprintf(ostream &out,const char *format,...)
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index 8669c97a5..b6e6bfdce 100644
--- a/apt-pkg/contrib/strutl.h
+++ b/apt-pkg/contrib/strutl.h
@@ -117,6 +117,8 @@ APT_PUBLIC std::vector<std::string> StringSplit(std::string const &input,
std::string const &sep,
unsigned int maxsplit=std::numeric_limits<unsigned int>::max()) APT_PURE;
+
+APT_HIDDEN bool iovprintf(std::ostream &out, const char *format, va_list &args, ssize_t &size);
APT_PUBLIC void ioprintf(std::ostream &out,const char *format,...) APT_PRINTF(2);
APT_PUBLIC void strprintf(std::string &out,const char *format,...) APT_PRINTF(2);
APT_PUBLIC char *safe_snprintf(char *Buffer,char *End,const char *Format,...) APT_PRINTF(3);