summaryrefslogtreecommitdiff
path: root/Source/cmLocale.h
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-02-06 13:23:07 -0500
committerBrad King <brad.king@kitware.com>2015-02-06 13:32:57 -0500
commitcd408d93fdf347ff63a8062f75f1f4ee3e898b17 (patch)
tree8fe5fcf05cd8092ccb1b80b0879c3928bec2af82 /Source/cmLocale.h
parent87be2e1427ba2b1b7697c9332487862917897dca (diff)
downloadcmake-cd408d93fdf347ff63a8062f75f1f4ee3e898b17.tar.gz
Add setlocale() calls around use of libarchive APIs (#14934, #15377)
The libarchive APIs use nl_langinfo(CODESET) for iconv so they need the locale to be set for LC_CTYPE. However, the rest of CMake does not define any behavior for non-ASCII character classification/conversion so we do not want to setlocale() globally. Add a RAII class to save, set, and restore the locale around calls to libarchive APIs. Inspired-by: Clinton Stimpson <clinton@elemtech.com>
Diffstat (limited to 'Source/cmLocale.h')
-rw-r--r--Source/cmLocale.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/Source/cmLocale.h b/Source/cmLocale.h
new file mode 100644
index 0000000000..727f0f5d40
--- /dev/null
+++ b/Source/cmLocale.h
@@ -0,0 +1,31 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2015 Kitware, Inc., Insight Software Consortium
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+#ifndef cmLocale_h
+#define cmLocale_h
+
+#include <locale.h>
+
+class cmLocaleRAII
+{
+ const char* OldLocale;
+public:
+ cmLocaleRAII(): OldLocale(setlocale(LC_CTYPE, 0))
+ {
+ setlocale(LC_CTYPE, "");
+ }
+ ~cmLocaleRAII()
+ {
+ setlocale(LC_CTYPE, this->OldLocale);
+ }
+};
+
+#endif