From 8b79c94af7f7cf2e5e5342294bc6e5a908cacabf Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 28 May 2016 13:22:38 +0200 Subject: [PATCH] use std::locale::global instead of setlocale We use a wild mixture of C and C++ ways of generating output, so having a consistent world-view in both styles sounds like a good idea and should help in preventing regressions. --- apt-private/private-main.cc | 4 +++- methods/aptmethod.h | 5 ++++- methods/cdrom.cc | 15 +++++++-------- methods/copy.cc | 7 +------ methods/file.cc | 6 +----- methods/ftp.cc | 10 ++-------- methods/ftp.h | 1 - methods/gpgv.cc | 7 +------ methods/http.cc | 1 - methods/http.h | 1 - methods/http_main.cc | 6 +----- methods/https.cc | 8 +------- methods/https.h | 3 +-- methods/mirror.cc | 7 +------ methods/mirror.h | 5 +---- methods/rred.cc | 4 +--- methods/rsh.cc | 6 +----- methods/rsh.h | 1 - methods/server.cc | 1 - methods/server.h | 1 - methods/store.cc | 6 +----- 21 files changed, 27 insertions(+), 78 deletions(-) diff --git a/apt-private/private-main.cc b/apt-private/private-main.cc index 9eb306834..0a9f4713f 100644 --- a/apt-private/private-main.cc +++ b/apt-private/private-main.cc @@ -7,6 +7,8 @@ #include #include +#include + #include #include #include @@ -16,7 +18,7 @@ void InitLocale() /*{{{*/ { - setlocale(LC_ALL,""); + std::locale::global(std::locale("")); textdomain(PACKAGE); } /*}}}*/ diff --git a/methods/aptmethod.h b/methods/aptmethod.h index f8a68c92b..cf3496e45 100644 --- a/methods/aptmethod.h +++ b/methods/aptmethod.h @@ -4,6 +4,7 @@ #include #include +#include #include class aptMethod : public pkgAcqMethod @@ -44,7 +45,9 @@ public: aptMethod(char const * const Binary, char const * const Ver, unsigned long const Flags) : pkgAcqMethod(Ver, Flags), Binary(Binary) - {} + { + std::locale::global(std::locale("")); + } }; #endif diff --git a/methods/cdrom.cc b/methods/cdrom.cc index d9ddecb6a..161822ac6 100644 --- a/methods/cdrom.cc +++ b/methods/cdrom.cc @@ -10,7 +10,6 @@ // Include Files /*{{{*/ #include -#include #include #include #include @@ -19,6 +18,8 @@ #include #include +#include "aptmethod.h" + #include #include #include @@ -29,7 +30,7 @@ using namespace std; -class CDROMMethod : public pkgAcqMethod +class CDROMMethod : public aptMethod { bool DatabaseLoaded; bool Debug; @@ -54,9 +55,9 @@ class CDROMMethod : public pkgAcqMethod // CDROMMethod::CDROMethod - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance | LocalOnly | +CDROMMethod::CDROMMethod() : aptMethod("cdrom", "1.0",SingleInstance | LocalOnly | SendConfig | NeedsCleanup | - Removable), + Removable), DatabaseLoaded(false), Debug(false), MountedByApt(false) @@ -279,8 +280,6 @@ bool CDROMMethod::Fetch(FetchItem *Itm) int main() { - setlocale(LC_ALL, ""); - - CDROMMethod Mth; - return Mth.Run(); + _config->CndSet("Binary::cdrom::Debug::NoDropPrivs", true); + return CDROMMethod().Run(); } diff --git a/methods/copy.cc b/methods/copy.cc index e515b2def..5e3654389 100644 --- a/methods/copy.cc +++ b/methods/copy.cc @@ -13,7 +13,6 @@ #include #include -#include #include #include #include @@ -95,9 +94,5 @@ bool CopyMethod::Fetch(FetchItem *Itm) int main() { - setlocale(LC_ALL, ""); - - CopyMethod Mth; - - return Mth.Run(); + return CopyMethod().Run(); } diff --git a/methods/file.cc b/methods/file.cc index 36f3c39b9..5cbf1924e 100644 --- a/methods/file.cc +++ b/methods/file.cc @@ -15,7 +15,6 @@ // Include Files /*{{{*/ #include -#include #include #include #include @@ -129,8 +128,5 @@ bool FileMethod::Fetch(FetchItem *Itm) int main() { - setlocale(LC_ALL, ""); - - FileMethod Mth; - return Mth.Run(); + return FileMethod().Run(); } diff --git a/methods/ftp.cc b/methods/ftp.cc index a8bc95938..6a886dd19 100644 --- a/methods/ftp.cc +++ b/methods/ftp.cc @@ -18,7 +18,6 @@ #include #include -#include #include #include #include @@ -1115,9 +1114,7 @@ bool FtpMethod::Fetch(FetchItem *Itm) /*}}}*/ int main(int, const char *argv[]) -{ - setlocale(LC_ALL, ""); - +{ /* See if we should be come the http client - we do this for http proxy urls */ if (getenv("ftp_proxy") != 0) @@ -1140,8 +1137,5 @@ int main(int, const char *argv[]) exit(100); } } - - FtpMethod Mth; - - return Mth.Run(); + return FtpMethod().Run(); } diff --git a/methods/ftp.h b/methods/ftp.h index de2c232bd..6a12475a0 100644 --- a/methods/ftp.h +++ b/methods/ftp.h @@ -10,7 +10,6 @@ #ifndef APT_FTP_H #define APT_FTP_H -#include #include #include "aptmethod.h" diff --git a/methods/gpgv.cc b/methods/gpgv.cc index dd395d659..fc6eb9159 100644 --- a/methods/gpgv.cc +++ b/methods/gpgv.cc @@ -1,6 +1,5 @@ #include -#include #include #include #include @@ -427,9 +426,5 @@ bool GPGVMethod::URIAcquire(std::string const &Message, FetchItem *Itm) int main() { - setlocale(LC_ALL, ""); - - GPGVMethod Mth; - - return Mth.Run(); + return GPGVMethod().Run(); } diff --git a/methods/http.cc b/methods/http.cc index 0c3803fbb..b861e61ee 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -28,7 +28,6 @@ #include #include -#include #include #include #include diff --git a/methods/http.h b/methods/http.h index 9e2b1da5c..5567de715 100644 --- a/methods/http.h +++ b/methods/http.h @@ -12,7 +12,6 @@ #define APT_HTTP_H #include -#include #include #include diff --git a/methods/http_main.cc b/methods/http_main.cc index cd52c42e8..fa183ddb3 100644 --- a/methods/http_main.cc +++ b/methods/http_main.cc @@ -7,13 +7,9 @@ int main() { - setlocale(LC_ALL, ""); - // ignore SIGPIPE, this can happen on write() if the socket // closes the connection (this is dealt with via ServerDie()) signal(SIGPIPE, SIG_IGN); - HttpMethod Mth; - - return Mth.Loop(); + return HttpMethod().Loop(); } diff --git a/methods/https.cc b/methods/https.cc index fc439bef8..35992ee96 100644 --- a/methods/https.cc +++ b/methods/https.cc @@ -13,7 +13,6 @@ #include #include -#include #include #include #include @@ -528,11 +527,6 @@ std::unique_ptr HttpsMethod::CreateServerState(URI const &uri)/*{{{ int main() { - setlocale(LC_ALL, ""); - - HttpsMethod Mth; - curl_global_init(CURL_GLOBAL_SSL) ; - - return Mth.Run(); + return HttpsMethod().Run(); } diff --git a/methods/https.h b/methods/https.h index 4d50c5a04..74b86a24f 100644 --- a/methods/https.h +++ b/methods/https.h @@ -11,8 +11,6 @@ #ifndef APT_HTTPS_H #define APT_HTTPS_H -#include - #include #include #include @@ -82,6 +80,7 @@ class HttpsMethod : public ServerMethod HttpsMethod() : ServerMethod("https","1.2",Pipeline | SendConfig) { + curl_global_init(CURL_GLOBAL_SSL); curl = curl_easy_init(); }; diff --git a/methods/mirror.cc b/methods/mirror.cc index 01eed09f0..9d900771b 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -465,11 +464,7 @@ void MirrorMethod::URIDone(FetchResult &Res,FetchResult *Alt) int main() { - setlocale(LC_ALL, ""); - - MirrorMethod Mth; - - return Mth.Loop(); + return MirrorMethod().Loop(); } diff --git a/methods/mirror.h b/methods/mirror.h index 425bea673..6ebe08e6b 100644 --- a/methods/mirror.h +++ b/methods/mirror.h @@ -1,6 +1,5 @@ // -*- mode: cpp; mode: fold -*- -// Description /*{{{*/// $Id: http.h,v 1.12 2002/04/18 05:09:38 jgg Exp $ -// $Id: http.h,v 1.12 2002/04/18 05:09:38 jgg Exp $ +// Description /*{{{*/ /* ###################################################################### MIRROR Acquire Method - This is the MIRROR acquire method for APT. @@ -11,8 +10,6 @@ #ifndef APT_MIRROR_H #define APT_MIRROR_H -#include - #include #include #include diff --git a/methods/rred.cc b/methods/rred.cc index 79ab8cb52..51af37557 100644 --- a/methods/rred.cc +++ b/methods/rred.cc @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -704,8 +703,7 @@ int main(int argc, char **argv) Patch patch; if (argc <= 1) { - RredMethod Mth; - return Mth.Run(); + return RredMethod().Run(); } // Usage: rred -t input output diff ... diff --git a/methods/rsh.cc b/methods/rsh.cc index 4d133951f..74a908ef7 100644 --- a/methods/rsh.cc +++ b/methods/rsh.cc @@ -17,7 +17,6 @@ #include #include #include -#include #include #include @@ -547,8 +546,5 @@ bool RSHMethod::Fetch(FetchItem *Itm) int main(int, const char *argv[]) { - setlocale(LC_ALL, ""); - - RSHMethod Mth(flNotDir(argv[0])); - return Mth.Run(); + return RSHMethod(flNotDir(argv[0])).Run(); } diff --git a/methods/rsh.h b/methods/rsh.h index 64a5cf661..571e38ba6 100644 --- a/methods/rsh.h +++ b/methods/rsh.h @@ -54,7 +54,6 @@ class RSHConn ~RSHConn(); }; -#include #include "aptmethod.h" class RSHMethod : public aptMethod diff --git a/methods/server.cc b/methods/server.cc index d606f26aa..9db45eb8c 100644 --- a/methods/server.cc +++ b/methods/server.cc @@ -10,7 +10,6 @@ // Include Files /*{{{*/ #include -#include #include #include #include diff --git a/methods/server.h b/methods/server.h index 3f6502432..1f90f6bd4 100644 --- a/methods/server.h +++ b/methods/server.h @@ -12,7 +12,6 @@ #define APT_SERVER_H #include -#include #include "aptmethod.h" #include diff --git a/methods/store.cc b/methods/store.cc index 2ad0f0177..934e1a188 100644 --- a/methods/store.cc +++ b/methods/store.cc @@ -14,7 +14,6 @@ #include #include -#include #include #include #include @@ -152,8 +151,5 @@ bool StoreMethod::Fetch(FetchItem *Itm) /*{{{*/ int main(int, char *argv[]) { - setlocale(LC_ALL, ""); - - StoreMethod Mth(flNotDir(argv[0])); - return Mth.Run(); + return StoreMethod(flNotDir(argv[0])).Run(); } -- 2.45.2