Browse Source

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.
David Kalnischkies 8 years ago
parent
commit
8b79c94af7

+ 3 - 1
apt-private/private-main.cc

@@ -7,6 +7,8 @@
 #include <apt-private/private-main.h>
 
 #include <iostream>
+#include <locale>
+
 #include <string.h>
 #include <unistd.h>
 #include <signal.h>
@@ -16,7 +18,7 @@
 
 void InitLocale()							/*{{{*/
 {
-   setlocale(LC_ALL,"");
+   std::locale::global(std::locale(""));
    textdomain(PACKAGE);
 }
 									/*}}}*/

+ 4 - 1
methods/aptmethod.h

@@ -4,6 +4,7 @@
 #include <apt-pkg/acquire-method.h>
 #include <apt-pkg/configuration.h>
 
+#include <locale>
 #include <string>
 
 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

+ 7 - 8
methods/cdrom.cc

@@ -10,7 +10,6 @@
 // Include Files							/*{{{*/
 #include <config.h>
 
-#include <apt-pkg/acquire-method.h>
 #include <apt-pkg/cdrom.h>
 #include <apt-pkg/cdromutl.h>
 #include <apt-pkg/error.h>
@@ -19,6 +18,8 @@
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/hashes.h>
 
+#include "aptmethod.h"
+
 #include <string>
 #include <vector>
 #include <sys/stat.h>
@@ -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();
 }

+ 1 - 6
methods/copy.cc

@@ -13,7 +13,6 @@
 
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/strutl.h>
-#include <apt-pkg/acquire-method.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/configuration.h>
@@ -95,9 +94,5 @@ bool CopyMethod::Fetch(FetchItem *Itm)
 
 int main()
 {
-   setlocale(LC_ALL, "");
-
-   CopyMethod Mth;
-
-   return Mth.Run();
+   return CopyMethod().Run();
 }

+ 1 - 5
methods/file.cc

@@ -15,7 +15,6 @@
 // Include Files							/*{{{*/
 #include <config.h>
 
-#include <apt-pkg/acquire-method.h>
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/hashes.h>
@@ -129,8 +128,5 @@ bool FileMethod::Fetch(FetchItem *Itm)
 
 int main()
 {
-   setlocale(LC_ALL, "");
-
-   FileMethod Mth;
-   return Mth.Run();
+   return FileMethod().Run();
 }

+ 2 - 8
methods/ftp.cc

@@ -18,7 +18,6 @@
 #include <config.h>
 
 #include <apt-pkg/fileutl.h>
-#include <apt-pkg/acquire-method.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/netrc.h>
@@ -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();
 }

+ 0 - 1
methods/ftp.h

@@ -10,7 +10,6 @@
 #ifndef APT_FTP_H
 #define APT_FTP_H
 
-#include <apt-pkg/acquire-method.h>
 #include <apt-pkg/strutl.h>
 #include "aptmethod.h"
 

+ 1 - 6
methods/gpgv.cc

@@ -1,6 +1,5 @@
 #include <config.h>
 
-#include <apt-pkg/acquire-method.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/gpgv.h>
@@ -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();
 }

+ 0 - 1
methods/http.cc

@@ -28,7 +28,6 @@
 #include <config.h>
 
 #include <apt-pkg/fileutl.h>
-#include <apt-pkg/acquire-method.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/hashes.h>

+ 0 - 1
methods/http.h

@@ -12,7 +12,6 @@
 #define APT_HTTP_H
 
 #include <apt-pkg/strutl.h>
-#include <apt-pkg/acquire-method.h>
 
 #include <string>
 #include <sys/time.h>

+ 1 - 5
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();
 }

+ 1 - 7
methods/https.cc

@@ -13,7 +13,6 @@
 #include <config.h>
 
 #include <apt-pkg/fileutl.h>
-#include <apt-pkg/acquire-method.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/netrc.h>
@@ -528,11 +527,6 @@ std::unique_ptr<ServerState> HttpsMethod::CreateServerState(URI const &uri)/*{{{
 
 int main()
 {
-   setlocale(LC_ALL, "");
-
-   HttpsMethod Mth;
-   curl_global_init(CURL_GLOBAL_SSL) ;
-
-   return Mth.Run();
+   return HttpsMethod().Run();
 }
 

+ 1 - 2
methods/https.h

@@ -11,8 +11,6 @@
 #ifndef APT_HTTPS_H
 #define APT_HTTPS_H
 
-#include <apt-pkg/acquire-method.h>
-
 #include <curl/curl.h>
 #include <iostream>
 #include <stddef.h>
@@ -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();
    };
 

+ 1 - 6
methods/mirror.cc

@@ -12,7 +12,6 @@
 
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/fileutl.h>
-#include <apt-pkg/acquire-method.h>
 #include <apt-pkg/acquire-item.h>
 #include <apt-pkg/acquire.h>
 #include <apt-pkg/error.h>
@@ -465,11 +464,7 @@ void MirrorMethod::URIDone(FetchResult &Res,FetchResult *Alt)
 
 int main()
 {
-   setlocale(LC_ALL, "");
-
-   MirrorMethod Mth;
-
-   return Mth.Loop();
+   return MirrorMethod().Loop();
 }
 
 

+ 1 - 4
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 <apt-pkg/acquire-method.h>
-
 #include <iostream>
 #include <string>
 #include <vector>

+ 1 - 3
methods/rred.cc

@@ -10,7 +10,6 @@
 #include <apt-pkg/init.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/error.h>
-#include <apt-pkg/acquire-method.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/configuration.h>
@@ -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 ...

+ 1 - 5
methods/rsh.cc

@@ -17,7 +17,6 @@
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/configuration.h>
-#include <apt-pkg/acquire-method.h>
 #include <apt-pkg/strutl.h>
 
 #include <stdlib.h>
@@ -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();
 }

+ 0 - 1
methods/rsh.h

@@ -54,7 +54,6 @@ class RSHConn
    ~RSHConn();
 };
 
-#include <apt-pkg/acquire-method.h>
 #include "aptmethod.h"
 
 class RSHMethod : public aptMethod

+ 0 - 1
methods/server.cc

@@ -10,7 +10,6 @@
 // Include Files							/*{{{*/
 #include <config.h>
 
-#include <apt-pkg/acquire-method.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.h>

+ 0 - 1
methods/server.h

@@ -12,7 +12,6 @@
 #define APT_SERVER_H
 
 #include <apt-pkg/strutl.h>
-#include <apt-pkg/acquire-method.h>
 #include "aptmethod.h"
 
 #include <time.h>

+ 1 - 5
methods/store.cc

@@ -14,7 +14,6 @@
 #include <config.h>
 
 #include <apt-pkg/configuration.h>
-#include <apt-pkg/acquire-method.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/hashes.h>
@@ -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();
 }