blob: 3aa50c9d4d65c8bd59839222025d716bc898c769 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrAutoLocaleSetter_DEFINED
#define GrAutoLocaleSetter_DEFINED
#include "GrTypes.h"
#if !defined(SK_BUILD_FOR_ANDROID)
#include <locale.h>
#endif
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
#include <xlocale.h>
#endif
/**
* Helper class for ensuring that we don't use the wrong locale when building shaders. Android
* doesn't support locale in the NDK, so this is a no-op there.
*/
class GrAutoLocaleSetter {
public:
GrAutoLocaleSetter (const char* name) {
#if defined(SK_BUILD_FOR_WIN)
fOldPerThreadLocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
fOldLocale = setlocale(LC_ALL, name);
#elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__)
fLocale = newlocale(LC_ALL, name, 0);
if (fLocale) {
fOldLocale = uselocale(fLocale);
}
#else
(void) name; // suppress unused param warning.
#endif
}
~GrAutoLocaleSetter () {
#if defined(SK_BUILD_FOR_WIN)
setlocale(LC_ALL, fOldLocale);
_configthreadlocale(fOldPerThreadLocale);
#elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__)
if (fLocale) {
uselocale(fOldLocale);
freelocale(fLocale);
}
#endif
}
private:
#if defined(SK_BUILD_FOR_WIN)
int fOldPerThreadLocale;
const char* fOldLocale;
#elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__)
locale_t fOldLocale;
locale_t fLocale;
#endif
};
#endif
|